mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
* fixes #14983 * allow bootstrapping with 0.20 * added a test case for the new system.add with a sink parameter * make npeg green again
This commit is contained in:
@@ -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) =
|
||||
|
||||
@@ -8,6 +8,8 @@ Hello
|
||||
2
|
||||
0
|
||||
List
|
||||
@["4", "5", "6", "", "", "a", ""]
|
||||
@["", "", "a", ""]
|
||||
'''
|
||||
cmd: '''nim c --gc:arc $file'''
|
||||
"""
|
||||
@@ -162,10 +164,21 @@ type
|
||||
case kind: TagKind
|
||||
of List:
|
||||
values: seq[Tag]
|
||||
of Compound:
|
||||
of Compound:
|
||||
compound: Table[string, Tag]
|
||||
|
||||
var a = Tag(kind: List)
|
||||
var b = a
|
||||
echo a.kind
|
||||
var c = a
|
||||
|
||||
proc testAdd(i: int; yyy: openArray[string]) =
|
||||
var x: seq[string]
|
||||
x.add [$i, $(i+1), $(i+2)]
|
||||
x.add yyy
|
||||
echo x
|
||||
|
||||
var y = newSeq[string](4)
|
||||
y[2] = "a"
|
||||
testAdd(4, y)
|
||||
echo y
|
||||
|
||||
Reference in New Issue
Block a user