shithub: mc

Download patch

ref: 4989e1b4e1184e1241c01d7d6f31a073d5a52a20
parent: 6933c334c2f597aabeb3a48eeda8da0981939bd5
author: Ori Bernstein <[email protected]>
date: Sat Jun 14 19:45:50 EDT 2014

Inline the swap function.

    It makes stuff faster.

--- a/libstd/sort.myr
+++ b/libstd/sort.myr
@@ -6,11 +6,14 @@
 
 generic sort = {sl, cmp
 	var end
+	var tmp
 
 	heapify(sl, cmp)
 	end = sl.len - 1
 	while end > 0
-		swap(sl, end, 0)
+		tmp = sl[end]
+		sl[end] = sl[0]
+		sl[0] = tmp
 		end--
 		siftdown(sl[:end], 0, cmp)
 	;;
@@ -29,6 +32,7 @@
 
 generic siftdown = {sl, start, cmp
 	var r, c, s
+	var tmp
 
 	r = start
 	while 2*r + 1 <= sl.len
@@ -43,18 +47,13 @@
 			;;
 		;;
 		if s != r
-			swap(sl, r, s)
+			tmp = sl[r]
+			sl[r] = sl[s]
+			sl[s] = tmp
 			r = s
 		else
 			->
 		;;
 	;;
-}
-
-generic swap = {sl, i, j
-	var tmp
-	tmp = sl[i]
-	sl[i] = sl[j]
-	sl[j] = tmp
 }