diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-08-14 23:33:06 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-08-14 23:33:06 +0100 |
commit | 261889c5b56b6610c370e2bd6ae78c0f81e22688 (patch) | |
tree | 5f035fc7d491fb4c8c61969e100b31ce7bf1ec8b /gen/src/gleam@list.erl | |
parent | ddba860d353d86c3daa8c3bf7054e9f73c43eac4 (diff) | |
download | gleam_stdlib-261889c5b56b6610c370e2bd6ae78c0f81e22688.tar.gz gleam_stdlib-261889c5b56b6610c370e2bd6ae78c0f81e22688.zip |
Slightly optimise list:sort
Diffstat (limited to 'gen/src/gleam@list.erl')
-rw-r--r-- | gen/src/gleam@list.erl | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/gen/src/gleam@list.erl b/gen/src/gleam@list.erl index 411a6c8..7781dcc 100644 --- a/gen/src/gleam@list.erl +++ b/gen/src/gleam@list.erl @@ -295,8 +295,7 @@ merge_sort(A, B, Compare) -> end end. -sort(List, Compare) -> - ListLength = length(List), +do_sort(List, Compare, ListLength) -> case ListLength < 2 of true -> List; @@ -305,9 +304,16 @@ sort(List, Compare) -> SplitLength = ListLength div 2, AList = take(List, SplitLength), BList = drop(List, SplitLength), - merge_sort(sort(AList, Compare), sort(BList, Compare), Compare) + merge_sort( + do_sort(AList, Compare, SplitLength), + do_sort(BList, Compare, ListLength - SplitLength), + Compare + ) end. +sort(List, Compare) -> + do_sort(List, Compare, length(List)). + range(Start, Stop) -> case gleam@int:compare(Start, Stop) of eq -> |