add overload add(a: var string, b: openArray[char])#15951
add overload add(a: var string, b: openArray[char])#15951timotheecour merged 9 commits intonim-lang:develfrom
add(a: var string, b: openArray[char])#15951Conversation
a96cf06 to
47773e9
Compare
|
While the intention here is good there are so many things in the stdlib that could benefit from using a more generic char sequence type (like in strutils) and openarray[char] is not the best candidate, lest we snowball into doing this everywhere. This change is however small and mirrors add(var seq[T], openarray[T]), so it's fine, except that that overload doesn't copy memory directly and uses move/sink instead |
|
A snowball has to start somewhere... 😼 |
string/seq/array implicitly converts to openArray[char], which is the main point; I'm not sure what your other "best candidate" is (apart from std/views see #14869 which has the advantage of being 1st class but doesn't implicitly convert from string/seq/array; only explicitly)
for openArray[char] (this PR) memcpy (or memmove if memory overlaps) is the correct thing to do; for the other existing overload with seq[T], we could/should do the same depending on |
a32d472 to
9104ef3
Compare
|
Can we add this to the new |
99fc861 to
c1649ac
Compare
done I'll followup with a PR to address this:
with some refactoring from compiler/strutils2 |
a73a474 to
69a3270
Compare
d658a9d to
d9245a1
Compare
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
- Required for a followup to nim-lang#15951 - Accompanies nim-lang#19727 but for strings + `sysstr` housekeeping: - Removed redundant `len` and `reserved` sets already performed by prior `rawNewStringNoInit`calls.
- Required for a followup to nim-lang#15951 - Accompanies nim-lang#19727 but for strings + `sysstr` housekeeping: - Removed redundant `len` and `reserved` sets already performed by prior `rawNewStringNoInit`calls.
- Required for a follow-up to nim-lang#15951 - Accompanies nim-lang#19727 but for strings - Expands `stdlib/tstring` with tests for `setLen` and `setLenUninit`
2 goals:
yopenArray to begin withfuture work
https://github.com/nim-lang/Nim/pull/15421/files#r522703485
addCstringNadd(a: var string, b: openArray[char])#15951 (comment) (see also follow up #15951 #17478)