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
|
|
@ -85,6 +85,7 @@
|
||||||
`replaceChildren`, `replaceWith`, `scrollIntoViewIfNeeded`, `setHTML`,
|
`replaceChildren`, `replaceWith`, `scrollIntoViewIfNeeded`, `setHTML`,
|
||||||
`toggleAttribute`, and `matches` to `std/dom`.
|
`toggleAttribute`, and `matches` to `std/dom`.
|
||||||
- Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
|
- Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
|
||||||
|
- Added `capacity` for `string` and `seq` to return the current capacity, see https://github.com/nim-lang/RFCs/issues/460
|
||||||
|
|
||||||
[//]: # "Deprecations:"
|
[//]: # "Deprecations:"
|
||||||
- Deprecated `selfExe` for Nimscript.
|
- Deprecated `selfExe` for Nimscript.
|
||||||
|
|
|
||||||
|
|
@ -129,3 +129,19 @@ proc setLen[T](s: var seq[T], newlen: Natural) =
|
||||||
proc newSeq[T](s: var seq[T], len: Natural) =
|
proc newSeq[T](s: var seq[T], len: Natural) =
|
||||||
shrink(s, 0)
|
shrink(s, 0)
|
||||||
setLen(s, len)
|
setLen(s, len)
|
||||||
|
|
||||||
|
|
||||||
|
template capacityImpl(sek: NimSeqV2): int =
|
||||||
|
if sek.p != nil: sek.p.cap else: 0
|
||||||
|
|
||||||
|
func capacity*[T](self: seq[T]): int {.inline.} =
|
||||||
|
## Returns the current capacity of the seq.
|
||||||
|
# See https://github.com/nim-lang/RFCs/issues/460
|
||||||
|
runnableExamples:
|
||||||
|
var lst = newSeqOfCap[string](cap = 42)
|
||||||
|
lst.add "Nim"
|
||||||
|
assert lst.capacity == 42
|
||||||
|
|
||||||
|
{.cast(noSideEffect).}:
|
||||||
|
let sek = unsafeAddr self
|
||||||
|
result = capacityImpl(cast[ptr NimSeqV2](sek)[])
|
||||||
|
|
|
||||||
|
|
@ -175,3 +175,19 @@ proc prepareMutation*(s: var string) {.inline.} =
|
||||||
{.cast(noSideEffect).}:
|
{.cast(noSideEffect).}:
|
||||||
let s = unsafeAddr s
|
let s = unsafeAddr s
|
||||||
nimPrepareStrMutationV2(cast[ptr NimStringV2](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