assign2: guard against self-assignment / overlapping openArray (#182)
This commit is contained in:
parent
8caa977199
commit
111d939940
|
@ -15,7 +15,7 @@ func assignImpl[T](tgt: var openArray[T], src: openArray[T]) =
|
||||||
mixin assign
|
mixin assign
|
||||||
when supportsCopyMem(T):
|
when supportsCopyMem(T):
|
||||||
if tgt.len > 0:
|
if tgt.len > 0:
|
||||||
copyMem(addr tgt[0], unsafeAddr src[0], sizeof(tgt[0]) * tgt.len)
|
moveMem(addr tgt[0], unsafeAddr src[0], sizeof(tgt[0]) * tgt.len)
|
||||||
else:
|
else:
|
||||||
for i in 0..<tgt.len:
|
for i in 0..<tgt.len:
|
||||||
assign(tgt[i], src[i])
|
assign(tgt[i], src[i])
|
||||||
|
@ -52,7 +52,7 @@ func assign*[T](tgt: var T, src: T) =
|
||||||
when sizeof(src) <= sizeof(int):
|
when sizeof(src) <= sizeof(int):
|
||||||
tgt = src
|
tgt = src
|
||||||
else:
|
else:
|
||||||
copyMem(addr tgt, unsafeAddr src, sizeof(tgt))
|
moveMem(addr tgt, unsafeAddr src, sizeof(tgt))
|
||||||
elif T is object|tuple:
|
elif T is object|tuple:
|
||||||
for t, s in fields(tgt, src):
|
for t, s in fields(tgt, src):
|
||||||
when supportsCopyMem(type s) and sizeof(s) <= sizeof(int) * 2:
|
when supportsCopyMem(type s) and sizeof(s) <= sizeof(int) * 2:
|
||||||
|
|
Loading…
Reference in New Issue