summaryrefslogtreecommitdiff
path: root/rts/js
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2023-02-24 10:02:50 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-28 11:11:21 -0500
commit8b77f9bfceb456115f63349ad0ff66a5cea7ab59 (patch)
tree5fc4cb971d4ce84177d1de266f799edf4c3e49eb /rts/js
parent0c200ab78c814cb5d1efaf426f0d3d91ceab9f4d (diff)
downloadhaskell-8b77f9bfceb456115f63349ad0ff66a5cea7ab59.tar.gz
JS: fix for overlap with copyMutableByteArray# (#23033)
The code wasn't taking into account some kind of overlap. cgrun070 has been extended to test the missing case.
Diffstat (limited to 'rts/js')
-rw-r--r--rts/js/mem.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/rts/js/mem.js b/rts/js/mem.js
index c1f586c282..3dcdc7979f 100644
--- a/rts/js/mem.js
+++ b/rts/js/mem.js
@@ -531,12 +531,17 @@ function h$sliceArray(a, start, n) {
return r;
}
+//////////////////////////////////////////////////////////
+//
// copy between two mutable arrays. Range may overlap
+// so we check which offset is bigger to make a front-to-back or
+// back-to-front traversal of the arrays.
+
function h$copyMutableArray(a1,o1,a2,o2,n) {
if (n <= 0) return;
if (o1 < o2) {
- for (var i=n-1;i>=0;i--) { // start from the end to handle potential overlap
+ for (var i=n-1;i>=0;i--) {
a2[o2+i] = a1[o1+i];
}
} else {
@@ -546,6 +551,22 @@ function h$copyMutableArray(a1,o1,a2,o2,n) {
}
}
+function h$copyMutableByteArray(a1,o1,a2,o2,n) {
+ if (n <= 0) return;
+
+ if (o1 < o2) {
+ for (var i=n-1;i>=0;i--) {
+ a2.u8[o2+i] = a1.u8[o1+i];
+ }
+ } else {
+ for (var i=0;i<n;i++) {
+ a2.u8[o2+i] = a1.u8[o1+i];
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////
+
function h$memcpy() {
if(arguments.length === 3) { // ByteArray# -> ByteArray# copy
var dst = arguments[0];