mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Fix capacity for const and shallow [backport] (#22705)
(cherry picked from commit b542be1e7d)
This commit is contained in:
committed by
narimiran
parent
fff127bec7
commit
ef8b8317ff
@@ -457,10 +457,6 @@ when not defined(js) and not defined(nimSeqsV2):
|
||||
data: UncheckedArray[char]
|
||||
NimString = ptr NimStringDesc
|
||||
|
||||
when notJSnotNims and not defined(nimSeqsV2):
|
||||
template space(s: PGenericSeq): int {.dirty.} =
|
||||
s.reserved and not (seqShallowFlag or strlitFlag)
|
||||
|
||||
when notJSnotNims:
|
||||
include "system/hti"
|
||||
|
||||
@@ -1068,6 +1064,10 @@ const
|
||||
hasThreadSupport = compileOption("threads") and not defined(nimscript)
|
||||
hasSharedHeap = defined(boehmgc) or defined(gogc) # don't share heaps; every thread has its own
|
||||
|
||||
when notJSnotNims and not defined(nimSeqsV2):
|
||||
template space(s: PGenericSeq): int =
|
||||
s.reserved and not (seqShallowFlag or strlitFlag)
|
||||
|
||||
when hasThreadSupport and defined(tcc) and not compileOption("tlsEmulation"):
|
||||
# tcc doesn't support TLS
|
||||
{.error: "`--tlsEmulation:on` must be used when using threads with tcc backend".}
|
||||
|
||||
@@ -150,7 +150,7 @@ func capacity*[T](self: seq[T]): int {.inline.} =
|
||||
assert lst.capacity == 42
|
||||
|
||||
let sek = cast[ptr NimSeqV2[T]](unsafeAddr self)
|
||||
result = if sek.p != nil: (sek.p.cap and not strlitFlag) else: 0
|
||||
result = if sek.p != nil: sek.p.cap and not strlitFlag else: 0
|
||||
|
||||
|
||||
{.pop.} # See https://github.com/nim-lang/Nim/issues/21401
|
||||
|
||||
@@ -211,4 +211,4 @@ func capacity*(self: string): int {.inline.} =
|
||||
assert str.capacity == 42
|
||||
|
||||
let str = cast[ptr NimStringV2](unsafeAddr self)
|
||||
result = if str.p != nil: str.p.cap else: 0
|
||||
result = if str.p != nil: str.p.cap and not strlitFlag else: 0
|
||||
|
||||
@@ -350,7 +350,7 @@ func capacity*(self: string): int {.inline.} =
|
||||
assert str.capacity == 42
|
||||
|
||||
let str = cast[NimString](self)
|
||||
result = if str != nil: str.reserved else: 0
|
||||
result = if str != nil: str.space else: 0
|
||||
|
||||
func capacity*[T](self: seq[T]): int {.inline.} =
|
||||
## Returns the current capacity of the seq.
|
||||
@@ -361,4 +361,4 @@ func capacity*[T](self: seq[T]): int {.inline.} =
|
||||
assert lst.capacity == 42
|
||||
|
||||
let sek = cast[PGenericSeq](self)
|
||||
result = if sek != nil: (sek.reserved and not strlitFlag) else: 0
|
||||
result = if sek != nil: sek.space else: 0
|
||||
|
||||
Reference in New Issue
Block a user