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.
This commit is contained in:
Anaminus 2015-02-19 07:26:53 -06:00
parent fcb70d0750
commit 59a3ca0a76
2 changed files with 5 additions and 6 deletions

View File

@ -369,9 +369,8 @@ func valueSortLess(a, b reflect.Value) bool {
} }
// Compare the contents of both arrays. // Compare the contents of both arrays.
al := a.Len() l := a.Len()
bl := b.Len() for i := 0; i < l; i++ {
for i := 0; i < al && i < bl; i++ {
av := a.Index(i) av := a.Index(i)
bv := b.Index(i) bv := b.Index(i)
if av.Interface() == bv.Interface() { if av.Interface() == bv.Interface() {
@ -379,7 +378,7 @@ func valueSortLess(a, b reflect.Value) bool {
} }
return valueSortLess(av, bv) return valueSortLess(av, bv)
} }
return al < bl return false
} }
unsupported: unsupported:

View File

@ -168,8 +168,8 @@ func TestSortValues(t *testing.T) {
}, },
// Array // 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([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})},
[]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{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})},
}, },
// Uintptrs. // Uintptrs.
{ {