core :: AbstractArrayRead :: copy_to
self
to an other array.var a = [1, 2, 3, 4]
var b = [10, 20, 30, 40, 50]
a.copy_to(1, 2, b, 2)
assert b == [10, 20, 2, 3, 50]
# Copy a portion of `self` to an other array.
#
# var a = [1, 2, 3, 4]
# var b = [10, 20, 30, 40, 50]
# a.copy_to(1, 2, b, 2)
# assert b == [10, 20, 2, 3, 50]
fun copy_to(start: Int, len: Int, dest: AbstractArray[E], new_start: Int)
do
if start < new_start then
var i = len
while i > 0 do
i -= 1
dest[new_start+i] = self[start+i]
end
else
var i = 0
while i < len do
dest[new_start+i] = self[start+i]
i += 1
end
end
end
lib/core/collection/array.nit:106,2--127,4
redef fun copy_to(start, len, dest, new_start)
do
# Fast code when source and destination are two arrays
if not dest isa Array[E] then
super
return
end
# Enlarge dest if required
var dest_len = new_start + len
if dest_len > dest.length then
dest.enlarge(dest_len)
dest.length = dest_len
end
# Get underlying native arrays
var items = self.items
if items == null then return
var dest_items = dest.items
assert dest_items != null
# Native copy
items.memmove(start, len, dest_items, new_start)
end
lib/core/collection/array.nit:375,2--399,4