summary refs log tree commit diff stats
path: root/lib/system.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-20 23:20:11 +0200
committerAraq <rumpf_a@web.de>2011-06-20 23:20:11 +0200
commitf1100356b1dc08558f51a6d360d272c000e1c4bd (patch)
tree1963a2c91c1a8e57ed42f4baf06eebc95445b1a5 /lib/system.nim
parentc3f11d1637cf8d07d06ba6032a52244d2e5eb6fb (diff)
downloadNim-f1100356b1dc08558f51a6d360d272c000e1c4bd.tar.gz
zipfiles compiles again; added system.shallowCopy
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-xlib/system.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 1837959c7..af948265f 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -801,18 +801,25 @@ 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]
 
+proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
+  ## use this instead of `=` for a `shallow copy`:idx:. The shallow copy
+  ## only changes the semantics for sequences and strings (and types which
+  ## contain those). Be careful with the changed semantics though! There 
+  ## is a reason why the default assignment does a deep copy of sequences
+  ## and strings.
+
 proc del*[T](x: var seq[T], i: int) {.noSideEffect.} = 
   ## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
   ## This is an O(1) operation.
   var xl = x.len
-  x[i] = x[xl-1]
+  shallowCopy(x[i], x[xl-1])
   setLen(x, xl-1)
   
 proc delete*[T](x: var seq[T], i: int) {.noSideEffect.} = 
   ## deletes the item at index `i` by moving ``x[i+1..]`` by one position.
   ## This is an O(n) operation.
   var xl = x.len
-  for j in i..xl-2: x[j] = x[j+1]
+  for j in i..xl-2: shallowCopy(x[j], x[j+1]) 
   setLen(x, xl-1)
   
 proc insert*[T](x: var seq[T], item: T, i = 0) {.noSideEffect.} =