nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
32fdc25
)
core/array: fix implementation of naive copy_to to avoid overwriting
author
Jean Privat
<jean@pryen.org>
Wed, 2 Dec 2015 18:22:42 +0000
(13:22 -0500)
committer
Jean Privat
<jean@pryen.org>
Wed, 2 Dec 2015 19:05:21 +0000
(14:05 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>
lib/core/collection/array.nit
patch
|
blob
|
history
diff --git
a/lib/core/collection/array.nit
b/lib/core/collection/array.nit
index
0896bab
..
e8f57c0
100644
(file)
--- a/
lib/core/collection/array.nit
+++ b/
lib/core/collection/array.nit
@@
-112,10
+112,18
@@
abstract class AbstractArrayRead[E]
fun copy_to(start: Int, len: Int, dest: AbstractArray[E], new_start: Int)
do
# TODO native one
- var i = len
- while i > 0 do
- i -= 1
- dest[new_start+i] = self[start+i]
+ 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