diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-09-25 08:49:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-25 08:49:21 +0200 |
commit | e9fa486493b5fa796cfd7d312b0004d5ee6ea6f5 (patch) | |
tree | caddde31e6b001b6cb7cf869ff82556866946c32 /lib | |
parent | 68ec7a018b85e978c437e776dfcc183cf7b79057 (diff) | |
download | Nim-e9fa486493b5fa796cfd7d312b0004d5ee6ea6f5.tar.gz |
fixes #14983 (#15320)
* fixes #14983 * allow bootstrapping with 0.20 * added a test case for the new system.add with a sink parameter * make npeg green again
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system.nim | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/lib/system.nim b/lib/system.nim index eefa84565..a9c45f8fa 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1215,24 +1215,51 @@ when defined(nimscript) or not defined(nimSeqsV2): ## Generic code becomes much easier to write if the Nim naming scheme is ## respected. -proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = - ## Generic proc for adding a container `y` to a container `x`. - ## - ## For containers that have an order, `add` means *append*. New generic - ## containers should also call their adding proc `add` for consistency. - ## Generic code becomes much easier to write if the Nim naming scheme is - ## respected. - ## - ## See also: - ## * `& proc <#&,seq[T][T],seq[T][T]>`_ - ## - ## .. code-block:: Nim - ## var s: seq[string] = @["test2","test2"] - ## s.add("test") # s <- @[test2, test2, test] - {.noSideEffect.}: - let xl = x.len - setLen(x, xl + y.len) - for i in 0..high(y): x[xl+i] = y[i] +when defined(gcDestructors): + proc add*[T](x: var seq[T], y: sink openArray[T]) {.noSideEffect.} = + ## Generic proc for adding a container `y` to a container `x`. + ## + ## For containers that have an order, `add` means *append*. New generic + ## containers should also call their adding proc `add` for consistency. + ## Generic code becomes much easier to write if the Nim naming scheme is + ## respected. + ## + ## See also: + ## * `& proc <#&,seq[T][T],seq[T][T]>`_ + ## + ## .. code-block:: Nim + ## var s: seq[string] = @["test2","test2"] + ## s.add("test") # s <- @[test2, test2, test] + {.noSideEffect.}: + let xl = x.len + setLen(x, xl + y.len) + for i in 0..high(y): + when nimvm: + # workaround the fact that the VM does not yet + # handle sink parameters properly: + x[xl+i] = y[i] + else: + x[xl+i] = move y[i] +else: + proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = + ## Generic proc for adding a container `y` to a container `x`. + ## + ## For containers that have an order, `add` means *append*. New generic + ## containers should also call their adding proc `add` for consistency. + ## Generic code becomes much easier to write if the Nim naming scheme is + ## respected. + ## + ## See also: + ## * `& proc <#&,seq[T][T],seq[T][T]>`_ + ## + ## .. code-block:: Nim + ## var s: seq[string] = @["test2","test2"] + ## s.add("test") # s <- @[test2, test2, test] + {.noSideEffect.}: + let xl = x.len + setLen(x, xl + y.len) + for i in 0..high(y): x[xl+i] = y[i] + when defined(nimSeqsV2): template movingCopy(a, b) = |