From 6ceb60444d7647fc62d692743ad98202c3669b8e Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 18 Dec 2014 13:22:53 -0800 Subject: [PATCH] sort: deduplicate inner loop of Stable benchmark old ns/op new ns/op delta BenchmarkStableInt1K 117212 116287 -0.79% BenchmarkStableInt64K 9632002 9587872 -0.46% BenchmarkStable1e4 40044309 39865644 -0.45% BenchmarkStable1e2 126985 126456 -0.42% BenchmarkStableString1K 389774 391052 +0.33% BenchmarkStable1e6 8183202516 8157693442 -0.31% Change-Id: I14e518ad49ecce3d1fc2b056e1acd5e5a2de8144 Reviewed-on: https://go-review.googlesource.com/1821 Reviewed-by: Brad Fitzpatrick --- src/sort/sort.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/sort/sort.go b/src/sort/sort.go index e980c295c32..63f8894a196 100644 --- a/src/sort/sort.go +++ b/src/sort/sort.go @@ -359,30 +359,25 @@ func symMerge(data Interface, a, m, b int) { mid := a + (b-a)/2 n := mid + m - start := 0 + var start, r int if m > mid { start = n - b - r, p := mid, n-1 - for start < r { - c := start + (r-start)/2 - if !data.Less(p-c, c) { - start = c + 1 - } else { - r = c - } - } + r = mid } else { start = a - r, p := m, n-1 - for start < r { - c := start + (r-start)/2 - if !data.Less(p-c, c) { - start = c + 1 - } else { - r = c - } + r = m + } + p := n - 1 + + for start < r { + c := start + (r-start)/2 + if !data.Less(p-c, c) { + start = c + 1 + } else { + r = c } } + end := n - start rotate(data, start, m, end) symMerge(data, a, start, mid)