This commit is contained in:
araq
2026-03-11 12:08:53 +01:00
parent f5a5874259
commit becf711b0d
3 changed files with 9 additions and 9 deletions

View File

@@ -1703,19 +1703,19 @@ when not (notJSnotNims and defined(nimSeqsV2)):
# Needed so modules imported by system (e.g. syncio) can reference these without guards.
when notJSnotNims:
# mm:refc: string = ptr NimStringDesc with data: UncheckedArray[char]
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect.} =
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect, tags: [].} =
let ns = cast[NimString](s)
if ns == nil: nil
else: cast[ptr UncheckedArray[char]](addr ns.data[start])
proc endStore*(s: var string) {.inline, noSideEffect.} = discard
proc endStore*(s: var string) {.inline, noSideEffect, tags: [].} = discard
template readRawData*(s: string; start = 0): ptr UncheckedArray[char] =
let ns = cast[NimString](s)
if ns == nil: nil
else: cast[ptr UncheckedArray[char]](addr ns.data[start])
else:
# JS/nimscript: callers are guarded by whenNotVmJsNims/when not defined(js)
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect.} = nil
proc endStore*(s: var string) {.inline, noSideEffect.} = discard
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect, tags: [].} = nil
proc endStore*(s: var string) {.inline, noSideEffect, tags: [].} = discard
template readRawData*(s: string; start = 0): ptr UncheckedArray[char] = nil
when not defined(js):

View File

@@ -187,7 +187,7 @@ proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl, inl.} =
if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag:
nimPrepareStrMutationImpl(s)
proc prepareMutation*(s: var string) {.inline.} =
proc prepareMutation*(s: var string) {.inline, tags: [].} =
# string literals are "copy on write", so you need to call
# `prepareMutation` before modifying the strings via `addr`.
{.cast(noSideEffect).}:
@@ -216,14 +216,14 @@ func capacity*(self: string): int {.inline.} =
let str = cast[ptr NimStringV2](unsafeAddr self)
result = if str.p != nil: str.p.cap and not strlitFlag else: 0
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect.} =
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect, tags: [].} =
## Returns a writable pointer for bulk write of `ensuredLen` bytes starting at `start`.
## Call `endStore(s)` afterwards for portability.
{.cast(noSideEffect).}: prepareMutation(s)
if s.len == 0: nil
else: cast[ptr UncheckedArray[char]](addr s[start])
proc endStore*(s: var string) {.inline, noSideEffect.} =
proc endStore*(s: var string) {.inline, noSideEffect, tags: [].} =
## No-op for non-SSO strings; call after bulk writes via `beginStore`.
discard

View File

@@ -675,7 +675,7 @@ proc completeStore(s: var SmallString) {.compilerproc, inline.} =
proc completeStore*(s: var string) {.inline.} =
completeStore(cast[ptr SmallString](addr s)[])
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect.} =
proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[char] {.inline, noSideEffect, tags: [].} =
## Prepares `s` for a bulk write of `ensuredLen` bytes starting at `start`.
## The caller must ensure `s.len >= start + ensuredLen` (e.g. via `newString` or `setLen`).
## Call `endStore(s)` afterwards to sync the inline cache.
@@ -688,7 +688,7 @@ proc beginStore*(s: var string; ensuredLen: int; start = 0): ptr UncheckedArray[
else:
result = cast[ptr UncheckedArray[char]](cast[uint](inlinePtr(ss[])) + uint(start))
proc endStore*(s: var string) {.inline, noSideEffect.} =
proc endStore*(s: var string) {.inline, noSideEffect, tags: [].} =
## Syncs the inline cache after bulk writes via `beginStore`. No-op for short/medium strings.
{.cast(noSideEffect).}: completeStore(cast[ptr SmallString](addr s)[])