fix zero length concat

This commit is contained in:
andri lim 2018-06-12 16:00:45 +07:00
parent 39f0a3cd03
commit af939d8ac4
2 changed files with 7 additions and 1 deletions

View File

@ -155,7 +155,8 @@ template toRange*[T](a: Range[T]): Range[T] = a
template copyRange[T](E: typedesc, dest: seq[T], destOffset: int, src: Range[T]) = template copyRange[T](E: typedesc, dest: seq[T], destOffset: int, src: Range[T]) =
when supportsCopyMem(E): when supportsCopyMem(E):
copyMem(dest[destOffset].unsafeAddr, src.start, sizeof(T) * src.len) if dest.len != 0 and src.len != 0:
copyMem(dest[destOffset].unsafeAddr, src.start, sizeof(T) * src.len)
else: else:
for i in 0..<src.len: for i in 0..<src.len:
dest[i + destOffset] = src[i] dest[i + destOffset] = src[i]

View File

@ -41,6 +41,11 @@ suite "Typed ranges":
var z = concat(b, @[7,8,9]) var z = concat(b, @[7,8,9])
check z == f check z == f
let u = toRange(newSeq[int](0))
let v = toRange(@[3])
check concat(u, v) == @[3]
check (v & u) == @[3]
test "complex types concat operation": test "complex types concat operation":
type type
Jaeger = object Jaeger = object