mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-24 15:41:43 +00:00
progress
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)[])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user