diff --git a/changelog.md b/changelog.md index 11930cf926d67..f64de4a204cf2 100644 --- a/changelog.md +++ b/changelog.md @@ -35,6 +35,8 @@ - `doAssertRaises` now correctly handles foreign exceptions. +- Added overload `ssytem.add(a: var string, b: openArray[char])` + ## Language changes - `nimscript` now handles `except Exception as e` diff --git a/lib/system.nim b/lib/system.nim index 1104cb17fee83..11fe8c31e6f39 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1032,6 +1032,18 @@ proc add*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.} ## tmp.add("cd") ## assert(tmp == "abcd") +proc add*(x: var string, y: openArray[char]) = + ## Concatenates `x` and `y` in place. `y` must not overlap with `x` to + ## allow future memcpy optimizations. + let n = x.len + x.setLen n + y.len + # pending https://github.com/nim-lang/Nim/issues/14655#issuecomment-643671397 + # use x.setLen(n + y.len, isInit = false) + var i=0 + while i