* remove `shallow` seqs/strings for ORC * add a changelog item * change url of DelaunayNim
This commit is contained in:
parent
964afd3050
commit
723a71bd22
9 changed files with 36 additions and 45 deletions
|
|
@ -53,7 +53,7 @@
|
||||||
or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma).
|
or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma).
|
||||||
Nim uses `Math.trunc` for the division and modulo operators for integers.
|
Nim uses `Math.trunc` for the division and modulo operators for integers.
|
||||||
|
|
||||||
- `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and
|
- `shallowCopy` and `shallow` are removed for ARC/ORC. Use `move` when possible or combine assignment and
|
||||||
`sink` for optimization purposes.
|
`sink` for optimization purposes.
|
||||||
|
|
||||||
- The `nimPreviewDotLikeOps` define is going to be removed or deprecated.
|
- The `nimPreviewDotLikeOps` define is going to be removed or deprecated.
|
||||||
|
|
|
||||||
14
doc/nimc.md
14
doc/nimc.md
|
|
@ -778,20 +778,6 @@ For `let` symbols a copy is not always necessary:
|
||||||
let s = varA # may only copy a pointer if it safe to do so
|
let s = varA # may only copy a pointer if it safe to do so
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
If you know what you're doing, you can also mark single-string (or sequence)
|
|
||||||
objects as `shallow`:idx:\:
|
|
||||||
|
|
||||||
```Nim
|
|
||||||
var s = "abc"
|
|
||||||
shallow(s) # mark 's' as a shallow string
|
|
||||||
var x = s # now might not copy the string!
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage of `shallow` is always safe once you know the string won't be modified
|
|
||||||
anymore, similar to Ruby's `freeze`:idx:.
|
|
||||||
|
|
||||||
|
|
||||||
The compiler optimizes string case statements: A hashing scheme is used for them
|
The compiler optimizes string case statements: A hashing scheme is used for them
|
||||||
if several different string constants are used. So code like this is reasonably
|
if several different string constants are used. So code like this is reasonably
|
||||||
efficient:
|
efficient:
|
||||||
|
|
|
||||||
|
|
@ -2313,29 +2313,30 @@ when compileOption("rangechecks"):
|
||||||
else:
|
else:
|
||||||
template rangeCheck*(cond) = discard
|
template rangeCheck*(cond) = discard
|
||||||
|
|
||||||
proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
|
when not defined(gcArc) and not defined(gcOrc):
|
||||||
## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
|
proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
|
||||||
## perform deep copies of `s`.
|
## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
|
||||||
##
|
## perform deep copies of `s`.
|
||||||
## This is only useful for optimization purposes.
|
##
|
||||||
if s.len == 0: return
|
## This is only useful for optimization purposes.
|
||||||
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
|
if s.len == 0: return
|
||||||
var s = cast[PGenericSeq](s)
|
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
|
||||||
s.reserved = s.reserved or seqShallowFlag
|
var s = cast[PGenericSeq](s)
|
||||||
|
|
||||||
proc shallow*(s: var string) {.noSideEffect, inline.} =
|
|
||||||
## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
|
|
||||||
## perform deep copies of `s`.
|
|
||||||
##
|
|
||||||
## This is only useful for optimization purposes.
|
|
||||||
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
|
|
||||||
var s = cast[PGenericSeq](s)
|
|
||||||
if s == nil:
|
|
||||||
s = cast[PGenericSeq](newString(0))
|
|
||||||
# string literals cannot become 'shallow':
|
|
||||||
if (s.reserved and strlitFlag) == 0:
|
|
||||||
s.reserved = s.reserved or seqShallowFlag
|
s.reserved = s.reserved or seqShallowFlag
|
||||||
|
|
||||||
|
proc shallow*(s: var string) {.noSideEffect, inline.} =
|
||||||
|
## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
|
||||||
|
## perform deep copies of `s`.
|
||||||
|
##
|
||||||
|
## This is only useful for optimization purposes.
|
||||||
|
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
|
||||||
|
var s = cast[PGenericSeq](s)
|
||||||
|
if s == nil:
|
||||||
|
s = cast[PGenericSeq](newString(0))
|
||||||
|
# string literals cannot become 'shallow':
|
||||||
|
if (s.reserved and strlitFlag) == 0:
|
||||||
|
s.reserved = s.reserved or seqShallowFlag
|
||||||
|
|
||||||
type
|
type
|
||||||
NimNodeObj = object
|
NimNodeObj = object
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ pkg "comprehension", "nimble test", "https://github.com/alehander92/comprehensio
|
||||||
pkg "criterion", allowFailure = true # pending https://github.com/disruptek/criterion/issues/3 (wrongly closed)
|
pkg "criterion", allowFailure = true # pending https://github.com/disruptek/criterion/issues/3 (wrongly closed)
|
||||||
pkg "datamancer"
|
pkg "datamancer"
|
||||||
pkg "dashing", "nim c tests/functional.nim"
|
pkg "dashing", "nim c tests/functional.nim"
|
||||||
pkg "delaunay"
|
pkg "delaunay", url = "https://github.com/nim-lang/DelaunayNim", useHead = true
|
||||||
pkg "docopt"
|
pkg "docopt"
|
||||||
pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
|
pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
|
||||||
pkg "elvis"
|
pkg "elvis"
|
||||||
|
|
|
||||||
|
|
@ -175,12 +175,14 @@ when not defined(nimseqsv2):
|
||||||
var emptySeq: seq[int] = newSeq[int]()
|
var emptySeq: seq[int] = newSeq[int]()
|
||||||
block:
|
block:
|
||||||
var t = @[1,2,3]
|
var t = @[1,2,3]
|
||||||
shallow(nilSeq)
|
when defined(gcRefc):
|
||||||
|
shallow(nilSeq)
|
||||||
t = nilSeq
|
t = nilSeq
|
||||||
doAssert t == @[]
|
doAssert t == @[]
|
||||||
block:
|
block:
|
||||||
var t = @[1,2,3]
|
var t = @[1,2,3]
|
||||||
shallow(emptySeq)
|
when defined(gcRefc):
|
||||||
|
shallow(emptySeq)
|
||||||
t = emptySeq
|
t = emptySeq
|
||||||
doAssert t == @[]
|
doAssert t == @[]
|
||||||
block:
|
block:
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
|
||||||
let e = if iend < 0: s.len + iend + 1
|
let e = if iend < 0: s.len + iend + 1
|
||||||
else: iend
|
else: iend
|
||||||
assert ibegin > 0 and e <= s.len
|
assert ibegin > 0 and e <= s.len
|
||||||
|
when defined(gcRefc):
|
||||||
shallow(s)
|
shallow(s)
|
||||||
result.bytes = s
|
result.bytes = s
|
||||||
result.ibegin = ibegin
|
result.ibegin = ibegin
|
||||||
result.iend = e
|
result.iend = e
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
|
||||||
let e = if iend < 0: s.len + iend + 1
|
let e = if iend < 0: s.len + iend + 1
|
||||||
else: iend
|
else: iend
|
||||||
assert ibegin >= 0 and e <= s.len
|
assert ibegin >= 0 and e <= s.len
|
||||||
|
when defined(gcRefc):
|
||||||
shallow(s)
|
shallow(s)
|
||||||
result.bytes = s
|
result.bytes = s
|
||||||
result.ibegin = ibegin
|
result.ibegin = ibegin
|
||||||
result.iend = e
|
result.iend = e
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ block: # setLen
|
||||||
block: # forceCopy
|
block: # forceCopy
|
||||||
var a: string
|
var a: string
|
||||||
a = "foo"
|
a = "foo"
|
||||||
shallow(a)
|
when defined(gcRefc):
|
||||||
|
shallow(a)
|
||||||
var b: string
|
var b: string
|
||||||
b = a
|
b = a
|
||||||
doAssert b[0].addr == a[0].addr
|
doAssert b[0].addr == a[0].addr
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ when true:
|
||||||
|
|
||||||
# casting an empty string as sequence with shallow() should not segfault
|
# casting an empty string as sequence with shallow() should not segfault
|
||||||
var s2: string
|
var s2: string
|
||||||
shallow(s2)
|
when defined(gcRefc):
|
||||||
|
shallow(s2)
|
||||||
s2 &= "foo"
|
s2 &= "foo"
|
||||||
doAssert s2 == "foo"
|
doAssert s2 == "foo"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue