Skip to content

Commit

Permalink
fixes #17173
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Mar 1, 2021
1 parent d35f366 commit f7198ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.

- Deprecated `any`. See https://github.com/nim-lang/RFCs/issues/281

- Added `std/sysrand` module to get random numbers from a secure source
- Added `std/sysrand` module to get random numbers from a secure source
provided by the operating system.

- Added optional `options` argument to `copyFile`, `copyFileToDir`, and
Expand Down Expand Up @@ -174,6 +174,9 @@ provided by the operating system.
of termination.

- Added `strip` and `setSlice` to `std/strbasics`.
- Added `system.prepareStrMutation` for better support of low
level `moveMem`, `copyMem` operations for Orc's copy-on-write string
implementation.


- Added to `wrapnils` an option-like API via `??.`, `isSome`, `get`.
Expand Down
4 changes: 3 additions & 1 deletion lib/std/strbasics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ func setSlice*(s: var string, slice: Slice[int]) =
when not declared(moveMem):
impl()
else:
when defined(gcDestructors):
prepareStrMutation(s)
moveMem(addr s[0], addr s[first], last - first + 1)
s.setLen(last - first + 1)

func strip*(a: var string, leading = true, trailing = true, chars: set[char] = whitespaces) {.inline.} =
## Inplace version of `strip`. Strips leading or
## Inplace version of `strip`. Strips leading or
## trailing `chars` (default: whitespace characters).
##
## If `leading` is true (default), leading `chars` are stripped.
Expand Down
3 changes: 3 additions & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3126,3 +3126,6 @@ export io

when not defined(createNimHcr) and not defined(nimscript):
include nimhcr

when not defined(gcDestructors):
proc prepareStrMutation*(s: var string) {.inline.} = discard
5 changes: 5 additions & 0 deletions lib/system/strs_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ proc nimPrepareStrMutationImpl(s: var NimStringV2) =
proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl, inline.} =
if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag:
nimPrepareStrMutationImpl(s)

proc prepareStrMutation*(s: var string) {.inline.} =
{.cast(noSideEffect).}:
let s = unsafeAddr s
nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[])

0 comments on commit f7198ea

Please sign in to comment.