RFC-460 implemented (#19771)
* RFC-460 implemented * RFC-460 implemented * RFC-460 implemented * Fix dumb GitHub autoupdate on changelog
This commit is contained in:
parent
e0c1159fb3
commit
ebb1b7af23
3 changed files with 33 additions and 0 deletions
|
|
@ -175,3 +175,19 @@ proc prepareMutation*(s: var string) {.inline.} =
|
|||
{.cast(noSideEffect).}:
|
||||
let s = unsafeAddr s
|
||||
nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[])
|
||||
|
||||
|
||||
template capacityImpl(str: NimStringV2): int =
|
||||
if str.p != nil: str.p.cap else: 0
|
||||
|
||||
func capacity*(self: string): int {.inline.} =
|
||||
## Returns the current capacity of the string.
|
||||
# See https://github.com/nim-lang/RFCs/issues/460
|
||||
runnableExamples:
|
||||
var str = newStringOfCap(cap = 42)
|
||||
str.add "Nim"
|
||||
assert str.capacity == 42
|
||||
|
||||
{.cast(noSideEffect).}:
|
||||
let str = unsafeAddr self
|
||||
result = capacityImpl(cast[ptr NimStringV2](str)[])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue