You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Creates a new list of the specified length where each element is
18
36
* initialized with the result of an initializer function. The initializer
@@ -27,17 +45,18 @@ from "runtime/dataStructures" include DataStructures
27
45
* @since v0.3.0
28
46
*/
29
47
provide let init = (length, fn) => {
30
-
// This method can be further improved by checking the length against a specific size
31
-
// and determining if it can be made tail-recursive, then use List.reverse on it.
32
-
// Which would be the same as OCaml does it in https://github.com/ocaml/ocaml/blob/03839754f46319aa36d9dad56940a6f3c3bcb48a/stdlib/list.ml#L79
33
-
let rec iter = (idx, length) => {
34
-
if (idx >= length) {
35
-
[]
36
-
} else {
37
-
[fn(idx), ...iter(idx + 1, length)]
48
+
if (length < 2048) {
49
+
// For small lists, use a faster non-tail-recursive version
0 commit comments