mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
use system.move instead of system.shallowCopy if the GC mode requires it
This commit is contained in:
@@ -201,7 +201,7 @@ iterator instantRows*(db: DbConn, query: SqlQuery,
|
||||
properFreeResult(sqlres, row)
|
||||
|
||||
proc setTypeName(t: var DbType; f: PFIELD) =
|
||||
shallowCopy(t.name, $f.name)
|
||||
t.name = $f.name
|
||||
t.maxReprLen = Natural(f.max_length)
|
||||
if (NOT_NULL_FLAG and f.flags) != 0: t.notNull = true
|
||||
case f.ftype
|
||||
|
||||
@@ -399,11 +399,14 @@ proc hash(x: IndexEntry): Hash =
|
||||
result = result !& x.linkDesc.hash
|
||||
result = !$result
|
||||
|
||||
proc `<-`(a: var IndexEntry, b: IndexEntry) =
|
||||
shallowCopy a.keyword, b.keyword
|
||||
shallowCopy a.link, b.link
|
||||
shallowCopy a.linkTitle, b.linkTitle
|
||||
shallowCopy a.linkDesc, b.linkDesc
|
||||
when defined(gcDestructors):
|
||||
template `<-`(a, b: var IndexEntry) = a = move(b)
|
||||
else:
|
||||
proc `<-`(a: var IndexEntry, b: IndexEntry) =
|
||||
shallowCopy a.keyword, b.keyword
|
||||
shallowCopy a.link, b.link
|
||||
shallowCopy a.linkTitle, b.linkTitle
|
||||
shallowCopy a.linkDesc, b.linkDesc
|
||||
|
||||
proc sortIndex(a: var openArray[IndexEntry]) =
|
||||
# we use shellsort here; fast and simple
|
||||
|
||||
@@ -325,8 +325,8 @@ proc upperBound*[T](a: openArray[T], key: T): int = upperBound(a, key, cmp[T])
|
||||
## * `lowerBound proc<#lowerBound,openArray[T],T>`_
|
||||
|
||||
template `<-` (a, b) =
|
||||
when false:
|
||||
a = b
|
||||
when defined(gcDestructors):
|
||||
a = move b
|
||||
elif onlySafeCode:
|
||||
shallowCopy(a, b)
|
||||
else:
|
||||
@@ -587,9 +587,7 @@ proc product*[T](x: openArray[seq[T]]): seq[seq[T]] =
|
||||
indexes[index] -= 1
|
||||
for ni, i in indexes:
|
||||
next[ni] = x[ni][i]
|
||||
var res: seq[T]
|
||||
shallowCopy(res, next)
|
||||
result.add(res)
|
||||
result.add(next)
|
||||
index = 0
|
||||
indexes[index] -= 1
|
||||
|
||||
|
||||
@@ -259,9 +259,11 @@ proc expandIfNeeded[T](deq: var Deque[T]) =
|
||||
var cap = deq.mask + 1
|
||||
if unlikely(deq.count >= cap):
|
||||
var n = newSeq[T](cap * 2)
|
||||
for i, x in pairs(deq): # don't use copyMem because the GC and because it's slower.
|
||||
shallowCopy(n[i], x)
|
||||
shallowCopy(deq.data, n)
|
||||
var i = 0
|
||||
for x in mitems(deq): # don't use copyMem because of the GC and because it's slower.
|
||||
n[i] = move(x)
|
||||
inc i
|
||||
deq.data = move(n)
|
||||
deq.mask = cap * 2 - 1
|
||||
deq.tail = deq.count
|
||||
deq.head = 0
|
||||
|
||||
@@ -417,7 +417,10 @@ proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
|
||||
for i in 0 ..< len(s):
|
||||
if pred(s[i]):
|
||||
if pos != i:
|
||||
shallowCopy(s[pos], s[i])
|
||||
when defined(gcDestructors):
|
||||
s[pos] = move(s[i])
|
||||
else:
|
||||
shallowCopy(s[pos], s[i])
|
||||
inc(pos)
|
||||
setLen(s, pos)
|
||||
|
||||
@@ -436,7 +439,10 @@ proc delete*[T](s: var seq[T]; first, last: Natural) =
|
||||
var j = min(len(s), last+1)
|
||||
var newLen = len(s)-j+i
|
||||
while i < newLen:
|
||||
s[i].shallowCopy(s[j])
|
||||
when defined(gcDestructors):
|
||||
s[i] = move(s[j])
|
||||
else:
|
||||
s[i].shallowCopy(s[j])
|
||||
inc(i)
|
||||
inc(j)
|
||||
setLen(s, newLen)
|
||||
@@ -461,7 +467,10 @@ proc insert*[T](dest: var seq[T], src: openArray[T], pos = 0) =
|
||||
|
||||
# Move items after `pos` to the end of the sequence.
|
||||
while j >= pos:
|
||||
dest[i].shallowCopy(dest[j])
|
||||
when defined(gcDestructors):
|
||||
dest[i] = move(dest[j])
|
||||
else:
|
||||
dest[i].shallowCopy(dest[j])
|
||||
dec(i)
|
||||
dec(j)
|
||||
# Insert items from `dest` into `dest` at `pos`
|
||||
@@ -519,7 +528,10 @@ template keepItIf*(varSeq: seq, pred: untyped) =
|
||||
let it {.inject.} = varSeq[i]
|
||||
if pred:
|
||||
if pos != i:
|
||||
shallowCopy(varSeq[pos], varSeq[i])
|
||||
when defined(gcDestructors):
|
||||
varSeq[pos] = move(varSeq[i])
|
||||
else:
|
||||
shallowCopy(varSeq[pos], varSeq[i])
|
||||
inc(pos)
|
||||
setLen(varSeq, pos)
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ proc exclImpl[A](s: var HashSet[A], key: A): bool {.inline.} =
|
||||
if isEmpty(s.data[i].hcode): # end of collision cluster; So all done
|
||||
return
|
||||
r = s.data[i].hcode and msk # "home" location of key@i
|
||||
shallowCopy(s.data[j], s.data[i]) # data[i] will be marked EMPTY next loop
|
||||
s.data[j] = move(s.data[i]) # data[i] will be marked EMPTY next loop
|
||||
|
||||
template dollarImpl() {.dirty.} =
|
||||
result = "{"
|
||||
|
||||
@@ -99,7 +99,7 @@ template delImplIdx(t, i) =
|
||||
when defined(js):
|
||||
t.data[j] = t.data[i]
|
||||
else:
|
||||
shallowCopy(t.data[j], t.data[i]) # data[j] will be marked EMPTY next loop
|
||||
t.data[j] = move(t.data[i]) # data[j] will be marked EMPTY next loop
|
||||
|
||||
template delImpl() {.dirty.} =
|
||||
var hc: Hash
|
||||
|
||||
@@ -540,7 +540,7 @@ proc take*[A, B](t: var Table[A, B], key: A, val: var B): bool =
|
||||
var index = rawGet(t, key, hc)
|
||||
result = index >= 0
|
||||
if result:
|
||||
shallowCopy(val, t.data[index].val)
|
||||
val = move(t.data[index].val)
|
||||
delImplIdx(t, index)
|
||||
|
||||
proc clear*[A, B](t: var Table[A, B]) =
|
||||
|
||||
@@ -846,17 +846,17 @@ elif not defined(useNimRtl):
|
||||
pipe(pStderr) != 0'i32:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
var sysCommand: string
|
||||
var data: StartProcessData
|
||||
var sysArgsRaw: seq[string]
|
||||
if poEvalCommand in options:
|
||||
const useShPath {.strdefine.} =
|
||||
when not defined(android): "/bin/sh"
|
||||
else: "/system/bin/sh"
|
||||
sysCommand = useShPath
|
||||
sysArgsRaw = @[sysCommand, "-c", command]
|
||||
data.sysCommand = useShPath
|
||||
sysArgsRaw = @[data.sysCommand, "-c", command]
|
||||
assert args.len == 0, "`args` has to be empty when using poEvalCommand."
|
||||
else:
|
||||
sysCommand = command
|
||||
data.sysCommand = command
|
||||
sysArgsRaw = @[command]
|
||||
for arg in args.items:
|
||||
sysArgsRaw.add arg
|
||||
@@ -873,8 +873,6 @@ elif not defined(useNimRtl):
|
||||
|
||||
defer: deallocCStringArray(sysEnv)
|
||||
|
||||
var data: StartProcessData
|
||||
shallowCopy(data.sysCommand, sysCommand)
|
||||
data.sysArgs = sysArgs
|
||||
data.sysEnv = sysEnv
|
||||
data.pStdin = pStdin
|
||||
|
||||
@@ -302,12 +302,18 @@ template piRest*(my: XmlParser): string =
|
||||
proc rawData*(my: XmlParser): string {.inline.} =
|
||||
## returns the underlying 'data' string by reference.
|
||||
## This is only used for speed hacks.
|
||||
shallowCopy(result, my.a)
|
||||
when defined(gcDestructors):
|
||||
result = move(my.a)
|
||||
else:
|
||||
shallowCopy(result, my.a)
|
||||
|
||||
proc rawData2*(my: XmlParser): string {.inline.} =
|
||||
## returns the underlying second 'data' string by reference.
|
||||
## This is only used for speed hacks.
|
||||
shallowCopy(result, my.b)
|
||||
when defined(gcDestructors):
|
||||
result = move(my.b)
|
||||
else:
|
||||
shallowCopy(result, my.b)
|
||||
|
||||
proc getColumn*(my: XmlParser): int {.inline.} =
|
||||
## get the current column the parser has arrived at.
|
||||
|
||||
@@ -311,7 +311,7 @@ proc write*[T](s: Stream, x: T) =
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
##
|
||||
## s.writeData(s, addr(x), sizeof(x))
|
||||
## s.writeData(s, unsafeAddr(x), sizeof(x))
|
||||
runnableExamples:
|
||||
var strm = newStringStream("")
|
||||
strm.write("abcde")
|
||||
@@ -319,9 +319,7 @@ proc write*[T](s: Stream, x: T) =
|
||||
doAssert strm.readAll() == "abcde"
|
||||
strm.close()
|
||||
|
||||
var y: T
|
||||
shallowCopy(y, x)
|
||||
writeData(s, addr(y), sizeof(y))
|
||||
writeData(s, unsafeAddr(x), sizeof(x))
|
||||
|
||||
proc write*(s: Stream, x: string) =
|
||||
## Writes the string `x` to the the stream `s`. No length field or
|
||||
|
||||
@@ -360,6 +360,8 @@ proc del*(t: StringTableRef, key: string) =
|
||||
break
|
||||
when defined(js):
|
||||
t.data[j] = t.data[i]
|
||||
elif defined(gcDestructors):
|
||||
t.data[j] = move t.data[i]
|
||||
else:
|
||||
shallowCopy(t.data[j], t.data[i]) # data[j] will be marked EMPTY next loop
|
||||
|
||||
|
||||
@@ -236,13 +236,19 @@ proc rawText*(n: XmlNode): string {.inline.} =
|
||||
## Returns the underlying 'text' string by reference.
|
||||
##
|
||||
## This is only used for speed hacks.
|
||||
shallowCopy(result, n.fText)
|
||||
when defined(gcDestructors):
|
||||
result = move(n.fText)
|
||||
else:
|
||||
shallowCopy(result, n.fText)
|
||||
|
||||
proc rawTag*(n: XmlNode): string {.inline.} =
|
||||
## Returns the underlying 'tag' string by reference.
|
||||
##
|
||||
## This is only used for speed hacks.
|
||||
shallowCopy(result, n.fTag)
|
||||
when defined(gcDestructors):
|
||||
result = move(n.fTag)
|
||||
else:
|
||||
shallowCopy(result, n.fTag)
|
||||
|
||||
proc innerText*(n: XmlNode): string =
|
||||
## Gets the inner text of `n`:
|
||||
|
||||
@@ -2104,7 +2104,7 @@ proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
|
||||
setLen(x, xl + y.len)
|
||||
for i in 0..high(y): x[xl+i] = y[i]
|
||||
|
||||
when defined(nimV2):
|
||||
when defined(gcDestructors):
|
||||
template movingCopy(a, b) =
|
||||
a = move(b)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user