mirror of https://github.com/golang/go.git
all: unindent some if bodies by exiting early
All of these had a return or break in the else body, so flipping the condition means we can unindent and simplify. Change-Id: If93e97504480d18a0dac3f2c8ffe57ab8bcb929c Reviewed-on: https://go-review.googlesource.com/74190 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
94484d8ed5
commit
7cb3e4fb1d
|
|
@ -1056,18 +1056,17 @@ func parName(f *types.Field, numbered bool) string {
|
||||||
// Take the name from the original, lest we substituted it with ~r%d or ~b%d.
|
// Take the name from the original, lest we substituted it with ~r%d or ~b%d.
|
||||||
// ~r%d is a (formerly) unnamed result.
|
// ~r%d is a (formerly) unnamed result.
|
||||||
if asNode(f.Nname) != nil {
|
if asNode(f.Nname) != nil {
|
||||||
if asNode(f.Nname).Orig != nil {
|
if asNode(f.Nname).Orig == nil {
|
||||||
s = asNode(f.Nname).Orig.Sym
|
|
||||||
if s != nil && s.Name[0] == '~' {
|
|
||||||
if s.Name[1] == 'r' { // originally an unnamed result
|
|
||||||
return "" // s = nil
|
|
||||||
} else if s.Name[1] == 'b' { // originally the blank identifier _
|
|
||||||
return "_" // belongs to localpkg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "" // s = nil
|
return "" // s = nil
|
||||||
}
|
}
|
||||||
|
s = asNode(f.Nname).Orig.Sym
|
||||||
|
if s != nil && s.Name[0] == '~' {
|
||||||
|
if s.Name[1] == 'r' { // originally an unnamed result
|
||||||
|
return "" // s = nil
|
||||||
|
} else if s.Name[1] == 'b' { // originally the blank identifier _
|
||||||
|
return "_" // belongs to localpkg
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
|
||||||
|
|
@ -2049,13 +2049,12 @@ func (ctxt *Link) address() {
|
||||||
// their section Vaddr, using n for index
|
// their section Vaddr, using n for index
|
||||||
n := 1
|
n := 1
|
||||||
for _, sect := range Segtext.Sections[1:] {
|
for _, sect := range Segtext.Sections[1:] {
|
||||||
if sect.Name == ".text" {
|
if sect.Name != ".text" {
|
||||||
symname := fmt.Sprintf("runtime.text.%d", n)
|
|
||||||
ctxt.xdefine(symname, sym.STEXT, int64(sect.Vaddr))
|
|
||||||
n++
|
|
||||||
} else {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
symname := fmt.Sprintf("runtime.text.%d", n)
|
||||||
|
ctxt.xdefine(symname, sym.STEXT, int64(sect.Vaddr))
|
||||||
|
n++
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.xdefine("runtime.rodata", sym.SRODATA, int64(rodata.Vaddr))
|
ctxt.xdefine("runtime.rodata", sym.SRODATA, int64(rodata.Vaddr))
|
||||||
|
|
|
||||||
|
|
@ -187,18 +187,18 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
encodedPart := simplePart + "*"
|
encodedPart := simplePart + "*"
|
||||||
if v, ok := pieceMap[encodedPart]; ok {
|
v, ok := pieceMap[encodedPart]
|
||||||
valid = true
|
if !ok {
|
||||||
if n == 0 {
|
break
|
||||||
if decv, ok := decode2231Enc(v); ok {
|
}
|
||||||
buf.WriteString(decv)
|
valid = true
|
||||||
}
|
if n == 0 {
|
||||||
} else {
|
if decv, ok := decode2231Enc(v); ok {
|
||||||
decv, _ := percentHexUnescape(v)
|
|
||||||
buf.WriteString(decv)
|
buf.WriteString(decv)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
decv, _ := percentHexUnescape(v)
|
||||||
|
buf.WriteString(decv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if valid {
|
if valid {
|
||||||
|
|
|
||||||
|
|
@ -1074,15 +1074,14 @@ func (v Value) MapIndex(key Value) Value {
|
||||||
typ := tt.elem
|
typ := tt.elem
|
||||||
fl := (v.flag | key.flag).ro()
|
fl := (v.flag | key.flag).ro()
|
||||||
fl |= flag(typ.Kind())
|
fl |= flag(typ.Kind())
|
||||||
if ifaceIndir(typ) {
|
if !ifaceIndir(typ) {
|
||||||
// Copy result so future changes to the map
|
|
||||||
// won't change the underlying value.
|
|
||||||
c := unsafe_New(typ)
|
|
||||||
typedmemmove(typ, c, e)
|
|
||||||
return Value{typ, c, fl | flagIndir}
|
|
||||||
} else {
|
|
||||||
return Value{typ, *(*unsafe.Pointer)(e), fl}
|
return Value{typ, *(*unsafe.Pointer)(e), fl}
|
||||||
}
|
}
|
||||||
|
// Copy result so future changes to the map
|
||||||
|
// won't change the underlying value.
|
||||||
|
c := unsafe_New(typ)
|
||||||
|
typedmemmove(typ, c, e)
|
||||||
|
return Value{typ, c, fl | flagIndir}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapKeys returns a slice containing all the keys present in the map,
|
// MapKeys returns a slice containing all the keys present in the map,
|
||||||
|
|
|
||||||
|
|
@ -338,15 +338,14 @@ func (m *machine) onepass(i input, pos, ncap int) bool {
|
||||||
if pos == 0 && syntax.EmptyOp(inst.Arg)&^flag == 0 &&
|
if pos == 0 && syntax.EmptyOp(inst.Arg)&^flag == 0 &&
|
||||||
len(m.re.prefix) > 0 && i.canCheckPrefix() {
|
len(m.re.prefix) > 0 && i.canCheckPrefix() {
|
||||||
// Match requires literal prefix; fast search for it.
|
// Match requires literal prefix; fast search for it.
|
||||||
if i.hasPrefix(m.re) {
|
if !i.hasPrefix(m.re) {
|
||||||
pos += len(m.re.prefix)
|
|
||||||
r, width = i.step(pos)
|
|
||||||
r1, width1 = i.step(pos + width)
|
|
||||||
flag = i.context(pos)
|
|
||||||
pc = int(m.re.prefixEnd)
|
|
||||||
} else {
|
|
||||||
return m.matched
|
return m.matched
|
||||||
}
|
}
|
||||||
|
pos += len(m.re.prefix)
|
||||||
|
r, width = i.step(pos)
|
||||||
|
r1, width1 = i.step(pos + width)
|
||||||
|
flag = i.context(pos)
|
||||||
|
pc = int(m.re.prefixEnd)
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
inst = m.op.Inst[pc]
|
inst = m.op.Inst[pc]
|
||||||
|
|
|
||||||
|
|
@ -352,20 +352,19 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) {
|
||||||
discardable := true // true if all cells in this column are empty and "soft"
|
discardable := true // true if all cells in this column are empty and "soft"
|
||||||
for ; this < line1; this++ {
|
for ; this < line1; this++ {
|
||||||
line = b.lines[this]
|
line = b.lines[this]
|
||||||
if column < len(line)-1 {
|
if column >= len(line)-1 {
|
||||||
// cell exists in this column
|
|
||||||
c := line[column]
|
|
||||||
// update width
|
|
||||||
if w := c.width + b.padding; w > width {
|
|
||||||
width = w
|
|
||||||
}
|
|
||||||
// update discardable
|
|
||||||
if c.width > 0 || c.htab {
|
|
||||||
discardable = false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// cell exists in this column
|
||||||
|
c := line[column]
|
||||||
|
// update width
|
||||||
|
if w := c.width + b.padding; w > width {
|
||||||
|
width = w
|
||||||
|
}
|
||||||
|
// update discardable
|
||||||
|
if c.width > 0 || c.htab {
|
||||||
|
discardable = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// column block end
|
// column block end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue