Skip to content

Commit 7ae6fd9

Browse files
committed
runtime: cleanup
Signed-off-by: Sora Morimoto <[email protected]>
1 parent dda4aa2 commit 7ae6fd9

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

runtime/array.js

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,12 @@
1919

2020
//Provides: caml_array_sub mutable
2121
function caml_array_sub(a, i, len) {
22-
const a2 = new Array(len + 1);
23-
a2[0] = 0;
24-
for (let i2 = 1, i1 = i + 1; i2 <= len; i2++, i1++) {
25-
a2[i2] = a[i1];
26-
}
27-
return a2;
22+
return [0, ...a.slice(i + 1, i + len + 1)];
2823
}
2924

3025
//Provides: caml_array_append mutable
3126
function caml_array_append(a1, a2) {
32-
const l1 = a1.length;
33-
const l2 = a2.length;
34-
const l = l1 + l2 - 1;
35-
const a = new Array(l);
36-
a[0] = 0;
37-
let i = 1;
38-
let j = 1;
39-
for (; i < l1; i++) a[i] = a1[i];
40-
for (; i < l; i++, j++) a[i] = a2[j];
41-
return a;
27+
return [0, ...a1.slice(1), ...a2.slice(1)];
4228
}
4329

4430
//Provides: caml_array_concat mutable
@@ -107,30 +93,19 @@ function caml_check_bound(array, index) {
10793
//Requires: caml_array_bound_error
10894
function caml_make_vect(len, init) {
10995
if (len < 0) caml_array_bound_error();
110-
const len_ = (len + 1) | 0;
111-
const b = new Array(len_);
112-
b[0] = 0;
113-
for (let i = 1; i < len_; i++) b[i] = init;
114-
return b;
96+
return [0, ...new Array(len | 0).fill(init)];
11597
}
11698

11799
//Provides: caml_make_float_vect const (const)
118100
//Requires: caml_array_bound_error
119101
function caml_make_float_vect(len) {
120102
if (len < 0) caml_array_bound_error();
121-
const len_ = (len + 1) | 0;
122-
const b = new Array(len);
123-
b[0] = 254;
124-
for (let i = 1; i < len_; i++) b[i] = 0;
125-
return b;
103+
return [254, ...new Array(len).fill(0)];
126104
}
105+
127106
//Provides: caml_floatarray_create const (const)
128107
//Requires: caml_array_bound_error
129108
function caml_floatarray_create(len) {
130109
if (len < 0) caml_array_bound_error();
131-
const len_ = (len + 1) | 0;
132-
const b = new Array(len);
133-
b[0] = 254;
134-
for (let i = 1; i < len_; i++) b[i] = 0;
135-
return b;
110+
return [254, ...new Array(len).fill(0)];
136111
}

0 commit comments

Comments
 (0)