mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 20:04:18 +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
@@ -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