diff options
-rw-r--r-- | lib/impure/db_mysql.nim | 2 | ||||
-rw-r--r-- | lib/packages/docutils/rstgen.nim | 13 | ||||
-rw-r--r-- | lib/pure/algorithm.nim | 8 | ||||
-rw-r--r-- | lib/pure/collections/deques.nim | 8 | ||||
-rw-r--r-- | lib/pure/collections/sequtils.nim | 20 | ||||
-rw-r--r-- | lib/pure/collections/setimpl.nim | 2 | ||||
-rw-r--r-- | lib/pure/collections/tableimpl.nim | 2 | ||||
-rw-r--r-- | lib/pure/collections/tables.nim | 2 | ||||
-rw-r--r-- | lib/pure/osproc.nim | 10 | ||||
-rw-r--r-- | lib/pure/parsexml.nim | 10 | ||||
-rw-r--r-- | lib/pure/streams.nim | 6 | ||||
-rw-r--r-- | lib/pure/strtabs.nim | 2 | ||||
-rw-r--r-- | lib/pure/xmltree.nim | 10 | ||||
-rw-r--r-- | lib/system.nim | 2 |
14 files changed, 61 insertions, 36 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index ba560243f..510503a63 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -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 diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index b75ff3ea1..e5536868b 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -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 diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 5d157dfc8..522ff1b16 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -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 diff --git a/lib/pure/collections/deques.nim b/lib/pure/collections/deques.nim index 7cea7d475..a9f8cd3c8 100644 --- a/lib/pure/collections/deques.nim +++ b/lib/pure/collections/deques.nim @@ -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 diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 9ca40de70..00bb0300d 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -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) diff --git a/lib/pure/collections/setimpl.nim b/lib/pure/collections/setimpl.nim index c3e05808f..d2d1490ff 100644 --- a/lib/pure/collections/setimpl.nim +++ b/lib/pure/collections/setimpl.nim @@ -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 = "{" diff --git a/lib/pure/collections/tableimpl.nim b/lib/pure/collections/tableimpl.nim index 7404a484b..85bffd60f 100644 --- a/lib/pure/collections/tableimpl.nim +++ b/lib/pure/collections/tableimpl.nim @@ -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 diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 74eb7ec74..3c91ba9c7 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -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]) = diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index d24740a16..4d1cc2280 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -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 diff --git a/lib/pure/parsexml.nim b/lib/pure/parsexml.nim index 576484231..16dc29caa 100644 --- a/lib/pure/parsexml.nim +++ b/lib/pure/parsexml.nim @@ -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. diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim index 0435e1f36..3850d10e2 100644 --- a/lib/pure/streams.nim +++ b/lib/pure/streams.nim @@ -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 diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index ca28e7766..4e40aab33 100644 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -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 diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index 408dbc23a..b23e00fdb 100644 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -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`: diff --git a/lib/system.nim b/lib/system.nim index 28d2e4be6..0edc869c2 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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: |