From 59a3ca0a768183d38b51c2b99687b8c48ba0771a Mon Sep 17 00:00:00 2001 From: Anaminus Date: Thu, 19 Feb 2015 07:26:53 -0600 Subject: [PATCH] Don't compare lengths of array keys when sorting. It isn't necessary for the sorter to compare the lengths of the two array keys, since they will always be equal. --- spew/common.go | 7 +++---- spew/common_test.go | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spew/common.go b/spew/common.go index 16fa209..d15a8a6 100644 --- a/spew/common.go +++ b/spew/common.go @@ -369,9 +369,8 @@ func valueSortLess(a, b reflect.Value) bool { } // Compare the contents of both arrays. - al := a.Len() - bl := b.Len() - for i := 0; i < al && i < bl; i++ { + l := a.Len() + for i := 0; i < l; i++ { av := a.Index(i) bv := b.Index(i) if av.Interface() == bv.Interface() { @@ -379,7 +378,7 @@ func valueSortLess(a, b reflect.Value) bool { } return valueSortLess(av, bv) } - return al < bl + return false } unsupported: diff --git a/spew/common_test.go b/spew/common_test.go index c5f08c7..8e741cd 100644 --- a/spew/common_test.go +++ b/spew/common_test.go @@ -168,8 +168,8 @@ func TestSortValues(t *testing.T) { }, // Array { - []reflect.Value{v([...]int{3, 2, 1}), v([...]int{1, 3, 2}), v([...]int{1, 2, 3}), v([...]int{}), v([...]int{2, 1})}, - []reflect.Value{v([...]int{}), v([...]int{1, 2, 3}), v([...]int{1, 3, 2}), v([...]int{2, 1}), v([...]int{3, 2, 1})}, + []reflect.Value{v([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})}, + []reflect.Value{v([3]int{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})}, }, // Uintptrs. {