aboutsummaryrefslogtreecommitdiff
path: root/gen
diff options
context:
space:
mode:
authorBrett Snyder <bsnyder@digitalocean.com>2019-05-15 07:22:03 -0500
committerLouis Pilfold <louis@lpil.uk>2019-05-15 17:32:50 +0100
commitee03f5a0465e176e220060164a5ffc408f73ed0d (patch)
tree1963a55b088684d78a5c575193edcc46f4e7738e /gen
parentaf07c099e69e296aaeabeebcb3e0a304bcb24d1d (diff)
downloadgleam_stdlib-ee03f5a0465e176e220060164a5ffc408f73ed0d.tar.gz
gleam_stdlib-ee03f5a0465e176e220060164a5ffc408f73ed0d.zip
optimize map:fold recursion
Diffstat (limited to 'gen')
-rw-r--r--gen/src/map_dict.erl13
1 files changed, 8 insertions, 5 deletions
diff --git a/gen/src/map_dict.erl b/gen/src/map_dict.erl
index e72b92d..5155ec7 100644
--- a/gen/src/map_dict.erl
+++ b/gen/src/map_dict.erl
@@ -75,12 +75,15 @@ update(Dict, Key, F) ->
put(Dict, Key, F({error, not_found}))
end.
-fold(Dict, Acc, F) ->
- Kvs = to_list(Dict),
- case Kvs of
+do_fold(List, Acc, F) ->
+ case List of
[] ->
Acc;
- [{K, V} | _] ->
- fold(delete(Dict, K), F(K, V, Acc), F)
+ [{K, V} | Tail] ->
+ do_fold(Tail, F(K, V, Acc), F)
end.
+
+fold(Dict, Acc, F) ->
+ Kvs = to_list(Dict),
+ do_fold(Kvs, Acc, F).