mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
By moving exported methods to the front of method lists, filtering down to only the exported methods just needs a count of how many exported methods exist, which the compiler can statically provide. This allows getting rid of the exported method cache. For #22075. Change-Id: I8eeb274563a2940e1347c34d673f843ae2569064 Reviewed-on: https://go-review.googlesource.com/100846 Reviewed-by: Ian Lance Taylor <iant@golang.org>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// 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 (
|
|
"cmd/compile/internal/types"
|
|
"cmd/internal/obj"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSortingBySigLT(t *testing.T) {
|
|
data := []*Sig{
|
|
&Sig{name: "b", pkg: &types.Pkg{Path: "abc"}},
|
|
&Sig{name: "B", pkg: nil},
|
|
&Sig{name: "C", pkg: nil},
|
|
&Sig{name: "c", pkg: &types.Pkg{Path: "uvw"}},
|
|
&Sig{name: "C", pkg: nil},
|
|
&Sig{name: "φ", pkg: &types.Pkg{Path: "gr"}},
|
|
&Sig{name: "Φ", pkg: nil},
|
|
&Sig{name: "b", pkg: &types.Pkg{Path: "xyz"}},
|
|
&Sig{name: "a", pkg: &types.Pkg{Path: "abc"}},
|
|
&Sig{name: "B", pkg: nil},
|
|
}
|
|
want := []*Sig{
|
|
&Sig{name: "B", pkg: nil},
|
|
&Sig{name: "B", pkg: nil},
|
|
&Sig{name: "C", pkg: nil},
|
|
&Sig{name: "C", pkg: nil},
|
|
&Sig{name: "Φ", pkg: nil},
|
|
&Sig{name: "a", pkg: &types.Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: &types.Pkg{Path: "abc"}},
|
|
&Sig{name: "b", pkg: &types.Pkg{Path: "xyz"}},
|
|
&Sig{name: "c", pkg: &types.Pkg{Path: "uvw"}},
|
|
&Sig{name: "φ", pkg: &types.Pkg{Path: "gr"}},
|
|
}
|
|
if len(data) != len(want) {
|
|
t.Fatal("want and data must match")
|
|
}
|
|
if reflect.DeepEqual(data, want) {
|
|
t.Fatal("data must be shuffled")
|
|
}
|
|
obj.SortSlice(data, func(i, j int) bool { return siglt(data[i], data[j]) })
|
|
if !reflect.DeepEqual(data, want) {
|
|
t.Logf("want: %#v", want)
|
|
t.Logf("data: %#v", data)
|
|
t.Errorf("sorting failed")
|
|
}
|
|
}
|