From a8fa4a61ed58cc3fd82e4a4178c9b77d08b89e82 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Tue, 12 Feb 2019 18:29:11 -0500 Subject: [PATCH 1/5] Account for File oddity in IE11 and IE10 --- src/Elm/Kernel/Debug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elm/Kernel/Debug.js b/src/Elm/Kernel/Debug.js index d2b04c98..f68ef007 100644 --- a/src/Elm/Kernel/Debug.js +++ b/src/Elm/Kernel/Debug.js @@ -148,7 +148,7 @@ function _Debug_toAnsiString(ansi, value) return _Debug_stringColor(ansi, '<' + value.byteLength + ' bytes>'); } - if (typeof File === 'function' && value instanceof File) + if (typeof File !== 'undefined' && value instanceof File) { return _Debug_internalColor(ansi, '<' + value.name + '>'); } From a017feba8f032b1113259f1748cbdaac98469b1d Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Fri, 3 May 2019 22:59:50 +0200 Subject: [PATCH 2/5] Improve performance of several functions. --- src/List.elm | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/List.elm b/src/List.elm index 9ef2b176..e23d3348 100644 --- a/src/List.elm +++ b/src/List.elm @@ -132,7 +132,17 @@ element (starting at zero). -} indexedMap : (Int -> a -> b) -> List a -> List b indexedMap f xs = - map2 f (range 0 (length xs - 1)) xs + reverse (indexedMapHelper 0 f xs []) + + +indexedMapHelper : (Int -> a -> b)->Int -> List a -> List b -> List b +indexedMapHelper fn index list result = + case list of + [] -> + result + + x :: xs -> + indexedMapHelper fn (index + 1) xs (cons (fn index x) result) {-| Reduce a list from the left. @@ -227,17 +237,16 @@ from an untrusted source and you want to turn them into numbers: -} filterMap : (a -> Maybe b) -> List a -> List b filterMap f xs = - foldr (maybeCons f) [] xs - - -maybeCons : (a -> Maybe b) -> a -> List b -> List b -maybeCons f mx xs = - case f mx of - Just x -> - cons x xs + let + helper mx acc = + case f mx of + Just x -> + cons x acc - Nothing -> - xs + Nothing -> + acc + in + foldr helper [] xs -- UTILITIES @@ -387,7 +396,12 @@ concat lists = -} concatMap : (a -> List b) -> List a -> List b concatMap f list = - concat (map f list) + let + helper val acc = + append (f val) acc + in + foldr helper [] list + {-| Places the given value between all members of the given list. From 199e7d908afeac7424e7a10996d19f582d4b5f64 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Fri, 3 May 2019 23:02:51 +0200 Subject: [PATCH 3/5] increase threshold of when foldr reverts to stack-safe implementation, to match that of take. --- src/List.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/List.elm b/src/List.elm index e23d3348..db727648 100644 --- a/src/List.elm +++ b/src/List.elm @@ -208,7 +208,7 @@ foldrHelper fn acc ctr ls = d :: r4 -> let res = - if ctr > 500 then + if ctr > 1000 then foldl fn acc (reverse r4) else foldrHelper fn acc (ctr + 1) r4 From 3e877b52054fc951f4bbcc916725050faccabe88 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Fri, 3 May 2019 23:09:33 +0200 Subject: [PATCH 4/5] Use native impl for List.append. --- src/Elm/Kernel/List.js | 17 +++++++++++++++++ src/Elm/Kernel/Utils.js | 14 ++------------ src/List.elm | 9 ++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Elm/Kernel/List.js b/src/Elm/Kernel/List.js index 2441718b..40f31af7 100644 --- a/src/Elm/Kernel/List.js +++ b/src/Elm/Kernel/List.js @@ -70,6 +70,23 @@ var _List_map5 = F6(function(f, vs, ws, xs, ys, zs) return _List_fromArray(arr); }); +var _List_append = F2(_List_ap); + +function _List_ap(xs, ys) +{ + if (!xs.b) + { + return ys; + } + var root = _List_Cons(xs.a, ys); + xs = xs.b + for (var curr = root; xs.b; xs = xs.b) // WHILE_CONS + { + curr = curr.b = _List_Cons(xs.a, ys); + } + return root; +} + var _List_sortBy = F2(function(f, xs) { return _List_fromArray(_List_toArray(xs).sort(function(a, b) { diff --git a/src/Elm/Kernel/Utils.js b/src/Elm/Kernel/Utils.js index 66406990..59a809d9 100644 --- a/src/Elm/Kernel/Utils.js +++ b/src/Elm/Kernel/Utils.js @@ -178,16 +178,6 @@ function _Utils_ap(xs, ys) return xs + ys; } - // append Lists - if (!xs.b) - { - return ys; - } - var root = __List_Cons(xs.a, ys); - xs = xs.b - for (var curr = root; xs.b; xs = xs.b) // WHILE_CONS - { - curr = curr.b = __List_Cons(xs.a, ys); - } - return root; + // append Lists + __List_ap(xs, ys); } diff --git a/src/List.elm b/src/List.elm index db727648..1fdb015f 100644 --- a/src/List.elm +++ b/src/List.elm @@ -372,13 +372,8 @@ product numbers = You can also use [the `(++)` operator](Basics#++) to append lists. -} append : List a -> List a -> List a -append xs ys = - case ys of - [] -> - xs - - _ -> - foldr cons ys xs +append = + Elm.Kernel.List.append {-| Concatenate a bunch of lists into a single list: From c9975bf73eefdaa5b7d5b41d1bd1b15dec854d41 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 4 May 2019 09:22:36 +0200 Subject: [PATCH 5/5] Add missing return Co-Authored-By: Skinney <854889+Skinney@users.noreply.github.com> --- src/Elm/Kernel/Utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elm/Kernel/Utils.js b/src/Elm/Kernel/Utils.js index 59a809d9..74fc2613 100644 --- a/src/Elm/Kernel/Utils.js +++ b/src/Elm/Kernel/Utils.js @@ -179,5 +179,5 @@ function _Utils_ap(xs, ys) } // append Lists - __List_ap(xs, ys); + return __List_ap(xs, ys); }