summaryrefslogtreecommitdiff
path: root/libstd/slcp.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-04-22 18:47:34 -0400
committerOri Bernstein <ori@eigenstate.org>2014-04-22 18:47:34 -0400
commit6ac0e591f2297ee9c3a5519844d9825e25db037b (patch)
tree9d894c48e7209559c65f4ac85d057da4ed279f8d /libstd/slcp.myr
parent1f979324794c81c3e8587b27c6124c640be9f9d5 (diff)
downloadmc-6ac0e591f2297ee9c3a5519844d9825e25db037b.tar.gz
Make slcp handle overlapping ranges correctly.
Diffstat (limited to 'libstd/slcp.myr')
-rw-r--r--libstd/slcp.myr24
1 files changed, 21 insertions, 3 deletions
diff --git a/libstd/slcp.myr b/libstd/slcp.myr
index 42813c8..71b5ca6 100644
--- a/libstd/slcp.myr
+++ b/libstd/slcp.myr
@@ -1,16 +1,34 @@
use "die.use"
+use "types.use"
pkg std =
generic slcp : (a : @a[:], b : @a[:] -> void)
;;
-generic slcp = {a, b
+generic slcp = {a : @a[:], b : @a[:]
var i
+ var addr_a, addr_b
assert(a.len == b.len, "arguments to slcp() must be of equal length")
- for i = 0; i < a.len; i++
- a[i] = b[i]
+ addr_a = a castto(@a#) castto(intptr)
+ addr_b = b castto(@a#) castto(intptr)
+ if forwardcopy(addr_a, addr_b)
+ for i = 0; i < a.len; i++
+ a[i] = b[i]
+ ;;
+ else
+ for i = a.len; i > 0; i--
+ a[i - 1] = b[i - 1]
+ ;;
;;
+
}
+const forwardcopy = {a, b
+ if a <= b
+ -> true
+ else
+ -> false
+ ;;
+}