Commit c1ad904b authored by Håvard Haugen's avatar Håvard Haugen Committed by Dave Cheney

cmd/compile/internal/gc: remove unnecessary stringsCompare

Remove several uses of stringsCompare.

Passes go build -a -toolexec 'toolstash -cmp' std cmd.

Change-Id: I3f2323df2ad8c03bad77e0a91d6e2e714803705b
Reviewed-on: https://go-review.googlesource.com/14556Reviewed-by: default avatarDave Cheney <dave@cheney.net>
parent 64ad5876
...@@ -253,21 +253,12 @@ func dumpexportvar(s *Sym) { ...@@ -253,21 +253,12 @@ func dumpexportvar(s *Sym) {
} }
} }
// methodbyname sorts types by symbol name.
type methodbyname []*Type type methodbyname []*Type
func (x methodbyname) Len() int { func (x methodbyname) Len() int { return len(x) }
return len(x) func (x methodbyname) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
} func (x methodbyname) Less(i, j int) bool { return x[i].Sym.Name < x[j].Sym.Name }
func (x methodbyname) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
func (x methodbyname) Less(i, j int) bool {
a := x[i]
b := x[j]
return stringsCompare(a.Sym.Name, b.Sym.Name) < 0
}
func dumpexporttype(t *Type) { func dumpexporttype(t *Type) {
if t == nil { if t == nil {
...@@ -289,24 +280,15 @@ func dumpexporttype(t *Type) { ...@@ -289,24 +280,15 @@ func dumpexporttype(t *Type) {
return return
} }
n := 0 var m []*Type
for f := t.Method; f != nil; f = f.Down { for f := t.Method; f != nil; f = f.Down {
dumpexporttype(f) dumpexporttype(f)
n++ m = append(m, f)
}
m := make([]*Type, n)
i := 0
for f := t.Method; f != nil; f = f.Down {
m[i] = f
i++
} }
sort.Sort(methodbyname(m[:n])) sort.Sort(methodbyname(m))
fmt.Fprintf(bout, "\ttype %v %v\n", Sconv(t.Sym, obj.FmtSharp), Tconv(t, obj.FmtSharp|obj.FmtLong)) fmt.Fprintf(bout, "\ttype %v %v\n", Sconv(t.Sym, obj.FmtSharp), Tconv(t, obj.FmtSharp|obj.FmtLong))
var f *Type for _, f := range m {
for i := 0; i < n; i++ {
f = m[i]
if f.Nointerface { if f.Nointerface {
fmt.Fprintf(bout, "\t//go:nointerface\n") fmt.Fprintf(bout, "\t//go:nointerface\n")
} }
......
...@@ -527,16 +527,11 @@ type TempVar struct { ...@@ -527,16 +527,11 @@ type TempVar struct {
removed bool // removed from program removed bool // removed from program
} }
// startcmp sorts TempVars by start, then id, then symbol name.
type startcmp []*TempVar type startcmp []*TempVar
func (x startcmp) Len() int { func (x startcmp) Len() int { return len(x) }
return len(x) func (x startcmp) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
}
func (x startcmp) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
func (x startcmp) Less(i, j int) bool { func (x startcmp) Less(i, j int) bool {
a := x[i] a := x[i]
b := x[j] b := x[j]
...@@ -556,7 +551,7 @@ func (x startcmp) Less(i, j int) bool { ...@@ -556,7 +551,7 @@ func (x startcmp) Less(i, j int) bool {
return int(a.def.Id-b.def.Id) < 0 return int(a.def.Id-b.def.Id) < 0
} }
if a.node != b.node { if a.node != b.node {
return stringsCompare(a.node.Sym.Name, b.node.Sym.Name) < 0 return a.node.Sym.Name < b.node.Sym.Name
} }
return false return false
} }
...@@ -709,7 +704,7 @@ func mergetemp(firstp *obj.Prog) { ...@@ -709,7 +704,7 @@ func mergetemp(firstp *obj.Prog) {
for i := 0; i < len(var_); i++ { for i := 0; i < len(var_); i++ {
bystart[i] = &var_[i] bystart[i] = &var_[i]
} }
sort.Sort(startcmp(bystart[:len(var_)])) sort.Sort(startcmp(bystart))
// List of in-use variables, sorted by end, so that the ones that // List of in-use variables, sorted by end, so that the ones that
// will last the longest are the earliest ones in the array. // will last the longest are the earliest ones in the array.
......
...@@ -607,16 +607,11 @@ func typ(et int) *Type { ...@@ -607,16 +607,11 @@ func typ(et int) *Type {
return t return t
} }
// methcmp sorts by symbol, then by package path for unexported symbols.
type methcmp []*Type type methcmp []*Type
func (x methcmp) Len() int { func (x methcmp) Len() int { return len(x) }
return len(x) func (x methcmp) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
}
func (x methcmp) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
func (x methcmp) Less(i, j int) bool { func (x methcmp) Less(i, j int) bool {
a := x[i] a := x[i]
b := x[j] b := x[j]
...@@ -627,16 +622,14 @@ func (x methcmp) Less(i, j int) bool { ...@@ -627,16 +622,14 @@ func (x methcmp) Less(i, j int) bool {
return true return true
} }
if b.Sym == nil { if b.Sym == nil {
return 1 < 0 return false
} }
k := stringsCompare(a.Sym.Name, b.Sym.Name) if a.Sym.Name != b.Sym.Name {
if k != 0 { return a.Sym.Name < b.Sym.Name
return k < 0
} }
if !exportname(a.Sym.Name) { if !exportname(a.Sym.Name) {
k := stringsCompare(a.Sym.Pkg.Path, b.Sym.Pkg.Path) if a.Sym.Pkg.Path != b.Sym.Pkg.Path {
if k != 0 { return a.Sym.Pkg.Path < b.Sym.Pkg.Path
return k < 0
} }
} }
...@@ -648,24 +641,19 @@ func sortinter(t *Type) *Type { ...@@ -648,24 +641,19 @@ func sortinter(t *Type) *Type {
return t return t
} }
i := 0 var a []*Type
for f := t.Type; f != nil; f = f.Down { for f := t.Type; f != nil; f = f.Down {
i++ a = append(a, f)
}
a := make([]*Type, i)
i = 0
var f *Type
for f = t.Type; f != nil; f = f.Down {
a[i] = f
i++
} }
sort.Sort(methcmp(a[:i])) sort.Sort(methcmp(a))
for i--; i >= 0; i-- {
a[i].Down = f n := len(a) // n > 0 due to initial conditions.
f = a[i] for i := 0; i < n-1; i++ {
a[i].Down = a[i+1]
} }
a[n-1].Down = nil
t.Type = f t.Type = a[0]
return t return t
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment