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:
parent
fcb70d0750
commit
59a3ca0a76
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue