Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix nim js cmp fails at CT

* followup nim-lang#16182
  • Loading branch information
ringabout authored and ardek66 committed Mar 26, 2021
1 parent 9e0561c commit 26ac585
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/pure/algorithm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ template `<-`(a, b) =
else:
copyMem(addr(a), addr(b), sizeof(T))

proc merge[T](a, b: var openArray[T], lo, m, hi: int,
proc mergeAlt[T](a, b: var openArray[T], lo, m, hi: int,
cmp: proc (x, y: T): int {.closure.}, order: SortOrder) =
# Optimization: If max(left) <= min(right) there is nothing to do!
# 1 2 3 4 ## 5 6 7 8
# -> O(n) for sorted arrays.
# On random data this saves up to 40% of merge calls.
# On random data this saves up to 40% of mergeAlt calls.
if cmp(a[m], a[m+1]) * order <= 0: return
var j = lo
# copy a[j..m] into b:
Expand Down Expand Up @@ -424,7 +424,7 @@ func sort*[T](a: var openArray[T],
while s < n:
var m = n-1-s
while m >= 0:
merge(a, b, max(m-s+1, 0), m, m+s, cmp, order)
mergeAlt(a, b, max(m-s+1, 0), m, m+s, cmp, order)
dec(m, s*2)
s = s*2

Expand Down

0 comments on commit 26ac585

Please sign in to comment.