|
19 | 19 |
|
20 | 20 | //Provides: caml_array_sub mutable |
21 | 21 | 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)]; |
28 | 23 | } |
29 | 24 |
|
30 | 25 | //Provides: caml_array_append mutable |
31 | 26 | 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)]; |
42 | 28 | } |
43 | 29 |
|
44 | 30 | //Provides: caml_array_concat mutable |
@@ -107,30 +93,19 @@ function caml_check_bound(array, index) { |
107 | 93 | //Requires: caml_array_bound_error |
108 | 94 | function caml_make_vect(len, init) { |
109 | 95 | 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)]; |
115 | 97 | } |
116 | 98 |
|
117 | 99 | //Provides: caml_make_float_vect const (const) |
118 | 100 | //Requires: caml_array_bound_error |
119 | 101 | function caml_make_float_vect(len) { |
120 | 102 | 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)]; |
126 | 104 | } |
| 105 | + |
127 | 106 | //Provides: caml_floatarray_create const (const) |
128 | 107 | //Requires: caml_array_bound_error |
129 | 108 | function caml_floatarray_create(len) { |
130 | 109 | 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)]; |
136 | 111 | } |
0 commit comments