mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/gc: use sort.Interface for reflect methods
Generate slices of method *Sig(nature)s instead of linked lists. Remove custom lsort function in favor of sort.Interface. Eliminates another use of stringsCompare. Passes go build -a -toolexec 'toolstash -cmp' std cmd. Change-Id: I9ed1664b7f55be9e967dd7196e396a76f6ea3422 Reviewed-on: https://go-review.googlesource.com/14559 Reviewed-by: Dave Cheney <dave@cheney.net>
This commit is contained in:
parent
ebd96933c1
commit
bca70a66a7
3 changed files with 117 additions and 149 deletions
47
src/cmd/compile/internal/gc/reflect_test.go
Normal file
47
src/cmd/compile/internal/gc/reflect_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSortingByMethodNameAndPackagePath(t *testing.T) {
|
||||
data := []*Sig{
|
||||
&Sig{name: "b", pkg: &Pkg{Path: "abc"}},
|
||||
&Sig{name: "b", pkg: nil},
|
||||
&Sig{name: "c", pkg: nil},
|
||||
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}},
|
||||
&Sig{name: "c", pkg: nil},
|
||||
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}},
|
||||
&Sig{name: "a", pkg: &Pkg{Path: "abc"}},
|
||||
&Sig{name: "b", pkg: nil},
|
||||
}
|
||||
want := []*Sig{
|
||||
&Sig{name: "a", pkg: &Pkg{Path: "abc"}},
|
||||
&Sig{name: "b", pkg: nil},
|
||||
&Sig{name: "b", pkg: nil},
|
||||
&Sig{name: "b", pkg: &Pkg{Path: "abc"}},
|
||||
&Sig{name: "b", pkg: &Pkg{Path: "xyz"}},
|
||||
&Sig{name: "c", pkg: nil},
|
||||
&Sig{name: "c", pkg: nil},
|
||||
&Sig{name: "c", pkg: &Pkg{Path: "uvw"}},
|
||||
}
|
||||
if len(data) != len(want) {
|
||||
t.Fatal("want and data must match")
|
||||
}
|
||||
if reflect.DeepEqual(data, want) {
|
||||
t.Fatal("data must be shuffled")
|
||||
}
|
||||
sort.Sort(byMethodNameAndPackagePath(data))
|
||||
if !reflect.DeepEqual(data, want) {
|
||||
t.Logf("want: %#v", want)
|
||||
t.Logf("data: %#v", data)
|
||||
t.Errorf("sorting failed")
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue