Skip to content

Commit b798490

Browse files
author
kutyel
committed
Change implementation 🚀
1 parent 6c5e3f7 commit b798490

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

jscomp/others/belt_Array.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ let reduceReverse2U a b x f =
362362
let reduceReverse2 a b x f =
363363
reduceReverse2U a b x (fun [@bs] a b c -> f a b c)
364364

365-
let rec reduceWithIndexAuxU a acc f i =
366-
match a with
367-
| [||] -> acc
368-
| x::xs -> reduceWithIndexAuxU xs ((f acc x i)[@bs]) f (i + 1)
369-
370-
let reduceWithIndexU a acc f = reduceWithIndexAuxU a acc f 0
365+
let reduceWithIndexU a x f =
366+
let r = ref x in
367+
for i = 0 to length a - 1 do
368+
r := f !r (getUnsafe a i) i [@bs]
369+
done;
370+
!r
371371

372-
let reduceWithIndex a acc f =
373-
reduceWithIndexU a acc (fun [@bs] acc x i -> f acc x i)
372+
let reduceWithIndex a x f =
373+
reduceWithIndexU a x (fun[@bs] a b c -> f a b c)
374374

375375
let rec everyAux arr i b len =
376376
if i = len then true

0 commit comments

Comments
 (0)