Skip to content

Commit 7569ec0

Browse files
committed
Optimize Array.partition by changing slice to truncateLength
1 parent 28a4824 commit 7569ec0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

jscomp/others/belt_Array.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ let partitionU a f =
425425
incr j
426426
)
427427
done;
428-
let a1 = slice a1 ~offset:0 ~len:!i in
429-
let a2 = slice a2 ~offset:0 ~len:!j in
428+
truncateToLengthUnsafe a1 !i;
429+
truncateToLengthUnsafe a2 !j;
430430
(a1, a2)
431431

432432
let partition a f = partitionU a (fun [@bs] x -> f x)

lib/js/belt_Array.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,11 @@ function partitionU(a, f) {
557557
j = j + 1 | 0;
558558
}
559559
}
560-
var a1$1 = slice(a1, 0, i);
561-
var a2$1 = slice(a2, 0, j);
560+
a1.length = i;
561+
a2.length = j;
562562
return /* tuple */[
563-
a1$1,
564-
a2$1
563+
a1,
564+
a2
565565
];
566566
}
567567

0 commit comments

Comments
 (0)