diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-06-04 15:32:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 15:32:46 -0700 |
commit | cc7ec5a6a42c2aead2c411228f023cbeff4220de (patch) | |
tree | 9fc84439da5076430c5edb52e8cf6ce39f1cc885 /lib | |
parent | a77360da5bad40d22e942cdd5cb9614c3548bf34 (diff) | |
download | Nim-cc7ec5a6a42c2aead2c411228f023cbeff4220de.tar.gz |
fix #7295: use move(result) inside template to avoid copy with --gc:refc (#18168)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/collections/sequtils.nim | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index e937b8394..6facfcc32 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -1014,27 +1014,27 @@ template applyIt*(varSeq, op: untyped) = template newSeqWith*(len: int, init: untyped): untyped = - ## Creates a new sequence of length `len`, calling `init` to initialize - ## each value of the sequence. - ## - ## Useful for creating "2D" sequences - sequences containing other sequences - ## or to populate fields of the created sequence. + ## Creates a new `seq` of length `len`, calling `init` to initialize + ## each value of the seq. ## + ## Useful for creating "2D" seqs - seqs containing other seqs + ## or to populate fields of the created seq. runnableExamples: - ## Creates a sequence containing 5 bool sequences, each of length of 3. + ## Creates a seq containing 5 bool seqs, each of length of 3. var seq2D = newSeqWith(5, newSeq[bool](3)) assert seq2D.len == 5 assert seq2D[0].len == 3 assert seq2D[4][2] == false - ## Creates a sequence of 20 random numbers from 1 to 10 - import random - var seqRand = newSeqWith(20, rand(10)) + ## Creates a seq with random numbers + import std/random + var seqRand = newSeqWith(20, rand(1.0)) + assert seqRand[0] != seqRand[1] var result = newSeq[typeof(init)](len) for i in 0 ..< len: result[i] = init - result + move(result) # refs bug #7295 func mapLitsImpl(constructor: NimNode; op: NimNode; nested: bool; filter = nnkLiterals): NimNode = |