RFC-460 implemented (#19771)

* RFC-460 implemented

* RFC-460 implemented

* RFC-460 implemented

* Fix dumb GitHub autoupdate on changelog
This commit is contained in:
Juan Carlos 2022-09-21 05:37:13 -03:00 • committed by GitHub
commit ebb1b7af23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -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)[])