mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-07 04:14:19 +00:00
deprecates newSeqUninitialized replaced by newSeqUninit (#22739)
ref #19727 closes #22586 https://github.com/nim-lang/Nim/issues/22554 needs it to move on. `newSeqUnsafe` can be introduced later.
This commit is contained in:
@@ -19,6 +19,7 @@ slots when enlarging a sequence.
|
||||
|
||||
[//]: # "Deprecations:"
|
||||
|
||||
- Deprecates `system.newSeqUninitialized`, which is replaced by `newSeqUninit`.
|
||||
|
||||
[//]: # "Removals:"
|
||||
|
||||
|
||||
@@ -627,7 +627,7 @@ proc newSeq*[T](len = 0.Natural): seq[T] =
|
||||
##
|
||||
## See also:
|
||||
## * `newSeqOfCap <#newSeqOfCap,Natural>`_
|
||||
## * `newSeqUninitialized <#newSeqUninitialized,Natural>`_
|
||||
## * `newSeqUninit <#newSeqUninit,Natural>`_
|
||||
newSeq(result, len)
|
||||
|
||||
proc newSeqOfCap*[T](cap: Natural): seq[T] {.
|
||||
@@ -1606,12 +1606,22 @@ when not defined(js) and defined(nimV2):
|
||||
flags: int
|
||||
PNimTypeV2 = ptr TNimTypeV2
|
||||
|
||||
proc supportsCopyMem(t: typedesc): bool {.magic: "TypeTrait".}
|
||||
|
||||
when notJSnotNims and defined(nimSeqsV2):
|
||||
include "system/strs_v2"
|
||||
include "system/seqs_v2"
|
||||
|
||||
when not defined(js):
|
||||
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
|
||||
template newSeqImpl(T, len) =
|
||||
result = newSeqOfCap[T](len)
|
||||
when defined(nimSeqsV2):
|
||||
cast[ptr int](addr result)[] = len
|
||||
else:
|
||||
var s = cast[PGenericSeq](result)
|
||||
s.len = len
|
||||
|
||||
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] {.deprecated: "Use `newSeqUninit` instead".} =
|
||||
## Creates a new sequence of type `seq[T]` with length `len`.
|
||||
##
|
||||
## Only available for numbers types. Note that the sequence will be
|
||||
@@ -1630,6 +1640,23 @@ when not defined(js):
|
||||
var s = cast[PGenericSeq](result)
|
||||
s.len = len
|
||||
|
||||
proc newSeqUninit*[T](len: Natural): seq[T] =
|
||||
## Creates a new sequence of type `seq[T]` with length `len`.
|
||||
##
|
||||
## Only available for types, which don't contain
|
||||
## managed memory or have destructors.
|
||||
## Note that the sequence will be uninitialized.
|
||||
## After the creation of the sequence you should assign
|
||||
## entries to the sequence instead of adding them.
|
||||
runnableExamples:
|
||||
var x = newSeqUninit[int](3)
|
||||
assert len(x) == 3
|
||||
x[0] = 10
|
||||
when supportsCopyMem(T):
|
||||
newSeqImpl(T, len)
|
||||
else:
|
||||
{.error: "The type T cannot contain managed memory or have destructors".}
|
||||
|
||||
proc newStringUninit*(len: Natural): string =
|
||||
## Returns a new string of length `len` but with uninitialized
|
||||
## content. One needs to fill the string character after character
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
{.push warning[StrictNotNil]: off.} # See https://github.com/nim-lang/Nim/issues/21401
|
||||
|
||||
|
||||
proc supportsCopyMem(t: typedesc): bool {.magic: "TypeTrait".}
|
||||
|
||||
## Default seq implementation used by Nim's core.
|
||||
type
|
||||
NimSeqPayloadBase = object
|
||||
|
||||
@@ -35,7 +35,7 @@ proc pkg(name: string; cmd = "nimble test"; url = "", useHead = true, allowFailu
|
||||
|
||||
pkg "alea"
|
||||
pkg "argparse"
|
||||
pkg "arraymancer", "nim c tests/tests_cpu.nim"
|
||||
pkg "arraymancer", "nim c tests/tests_cpu.nim", url = "https://github.com/nim-lang/Arraymancer"
|
||||
pkg "ast_pattern_matching", "nim c -r tests/test1.nim"
|
||||
pkg "asyncftpclient", "nimble compileExample"
|
||||
pkg "asyncthreadpool", "nimble test --mm:refc"
|
||||
@@ -96,7 +96,7 @@ pkg "measuremancer", "nimble testDeps; nimble -y test"
|
||||
pkg "memo"
|
||||
pkg "msgpack4nim", "nim c -r tests/test_spec.nim"
|
||||
pkg "nake", "nim c nakefile.nim"
|
||||
pkg "neo", "nim c -d:blas=openblas --mm:refc tests/all.nim"
|
||||
pkg "neo", "nim c -d:blas=openblas --mm:refc tests/all.nim", url = "https://github.com/nim-lang/neo"
|
||||
pkg "nesm", "nimble tests", "https://github.com/nim-lang/NESM", useHead = true
|
||||
pkg "netty"
|
||||
pkg "nico", allowFailure = true
|
||||
|
||||
Reference in New Issue
Block a user