mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: simplify multiple for loops
If a for loop has a simple condition and begins with a simple
"if x { break; }"; we can simply add "!x" to the loop's condition.
While at it, simplify a few assignments to use the common pattern
"x := staticDefault; if cond { x = otherValue(); }".
Finally, simplify a couple of var declarations.
Change-Id: I413982c6abd32905adc85a9a666cb3819139c19f
Reviewed-on: https://go-review.googlesource.com/c/go/+/165342
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
ce7534ff06
commit
49662bc6b0
13 changed files with 13 additions and 43 deletions
|
|
@ -553,11 +553,9 @@ func createDwarfVars(fnsym *obj.LSym, fn *Func, automDecls []*Node) ([]*Node, []
|
|||
decls, vars, selected = createSimpleVars(automDecls)
|
||||
}
|
||||
|
||||
var dcl []*Node
|
||||
dcl := automDecls
|
||||
if fnsym.WasInlined() {
|
||||
dcl = preInliningDcls(fnsym)
|
||||
} else {
|
||||
dcl = automDecls
|
||||
}
|
||||
|
||||
// If optimization is enabled, the list above will typically be
|
||||
|
|
|
|||
|
|
@ -477,12 +477,10 @@ func dimportpath(p *types.Pkg) {
|
|||
return
|
||||
}
|
||||
|
||||
var str string
|
||||
str := p.Path
|
||||
if p == localpkg {
|
||||
// Note: myimportpath != "", or else dgopkgpath won't call dimportpath.
|
||||
str = myimportpath
|
||||
} else {
|
||||
str = p.Path
|
||||
}
|
||||
|
||||
s := Ctxt.Lookup("type..importpath." + p.Prefix + ".")
|
||||
|
|
|
|||
|
|
@ -3116,11 +3116,9 @@ func walkcompare(n *Node, init *Nodes) *Node {
|
|||
if l != nil {
|
||||
// Handle both == and !=.
|
||||
eq := n.Op
|
||||
var andor Op
|
||||
andor := OOROR
|
||||
if eq == OEQ {
|
||||
andor = OANDAND
|
||||
} else {
|
||||
andor = OOROR
|
||||
}
|
||||
// Check for types equal.
|
||||
// For empty interface, this is:
|
||||
|
|
|
|||
|
|
@ -233,14 +233,10 @@ func schedule(f *Func) {
|
|||
// Schedule highest priority value, update use counts, repeat.
|
||||
order = order[:0]
|
||||
tuples := make(map[ID][]*Value)
|
||||
for {
|
||||
for priq.Len() > 0 {
|
||||
// Find highest priority schedulable value.
|
||||
// Note that schedule is assembled backwards.
|
||||
|
||||
if priq.Len() == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
v := heap.Pop(priq).(*Value)
|
||||
|
||||
// Add it to the schedule.
|
||||
|
|
|
|||
|
|
@ -141,10 +141,7 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) {
|
|||
continue
|
||||
}
|
||||
q := sym.Func.Text
|
||||
for q != nil {
|
||||
if p.To.Offset == q.Pc {
|
||||
break
|
||||
}
|
||||
for q != nil && p.To.Offset != q.Pc {
|
||||
if q.Forwd != nil && p.To.Offset >= q.Forwd.Pc {
|
||||
q = q.Forwd
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1290,11 +1290,9 @@ func elfshreloc(arch *sys.Arch, sect *sym.Section) *ElfShdr {
|
|||
return nil
|
||||
}
|
||||
|
||||
var typ int
|
||||
typ := SHT_REL
|
||||
if elfRelType == ".rela" {
|
||||
typ = SHT_RELA
|
||||
} else {
|
||||
typ = SHT_REL
|
||||
}
|
||||
|
||||
sh := elfshname(elfRelType + sect.Name)
|
||||
|
|
|
|||
|
|
@ -1069,8 +1069,7 @@ func typeFields(t reflect.Type) []field {
|
|||
next := []field{{typ: t}}
|
||||
|
||||
// Count of queued names for current level and the next.
|
||||
count := map[reflect.Type]int{}
|
||||
nextCount := map[reflect.Type]int{}
|
||||
var count, nextCount map[reflect.Type]int
|
||||
|
||||
// Types already visited at an earlier level.
|
||||
visited := map[reflect.Type]bool{}
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ type decodeThis struct {
|
|||
v interface{}
|
||||
}
|
||||
|
||||
var tokenStreamCases []tokenStreamCase = []tokenStreamCase{
|
||||
var tokenStreamCases = []tokenStreamCase{
|
||||
// streaming token cases
|
||||
{json: `10`, expTokens: []interface{}{float64(10)}},
|
||||
{json: ` [10] `, expTokens: []interface{}{
|
||||
|
|
|
|||
|
|
@ -510,10 +510,7 @@ func (t *rtype) Name() string {
|
|||
}
|
||||
s := t.String()
|
||||
i := len(s) - 1
|
||||
for i >= 0 {
|
||||
if s[i] == '.' {
|
||||
break
|
||||
}
|
||||
for i >= 0 && s[i] != '.' {
|
||||
i--
|
||||
}
|
||||
return s[i+1:]
|
||||
|
|
|
|||
|
|
@ -875,10 +875,7 @@ func (t *rtype) Name() string {
|
|||
}
|
||||
s := t.String()
|
||||
i := len(s) - 1
|
||||
for i >= 0 {
|
||||
if s[i] == '.' {
|
||||
break
|
||||
}
|
||||
for i >= 0 && s[i] != '.' {
|
||||
i--
|
||||
}
|
||||
return s[i+1:]
|
||||
|
|
|
|||
|
|
@ -1289,10 +1289,7 @@ func printCgoTraceback(callers *cgoCallers) {
|
|||
func printOneCgoTraceback(pc uintptr, max int, arg *cgoSymbolizerArg) int {
|
||||
c := 0
|
||||
arg.pc = pc
|
||||
for {
|
||||
if c > max {
|
||||
break
|
||||
}
|
||||
for c <= max {
|
||||
callCgoSymbolizer(arg)
|
||||
if arg.funcName != nil {
|
||||
// Note that we don't print any argument
|
||||
|
|
|
|||
|
|
@ -118,10 +118,7 @@ func (t *_type) name() string {
|
|||
}
|
||||
s := t.string()
|
||||
i := len(s) - 1
|
||||
for i >= 0 {
|
||||
if s[i] == '.' {
|
||||
break
|
||||
}
|
||||
for i >= 0 && s[i] != '.' {
|
||||
i--
|
||||
}
|
||||
return s[i+1:]
|
||||
|
|
|
|||
|
|
@ -263,11 +263,9 @@ func call(fn reflect.Value, args ...reflect.Value) (reflect.Value, error) {
|
|||
for i, arg := range args {
|
||||
value := indirectInterface(arg)
|
||||
// Compute the expected type. Clumsy because of variadics.
|
||||
var argType reflect.Type
|
||||
argType := dddType
|
||||
if !typ.IsVariadic() || i < numIn-1 {
|
||||
argType = typ.In(i)
|
||||
} else {
|
||||
argType = dddType
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue