mirror of
https://github.com/golang/go
synced 2024-11-19 14:54:43 -07:00
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.
|
||||
// ~r%d is a (formerly) unnamed result.
|
||||
if asNode(f.Nname) != 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 {
|
||||
if asNode(f.Nname).Orig == 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 {
|
||||
|
@ -2049,13 +2049,12 @@ func (ctxt *Link) address() {
|
||||
// their section Vaddr, using n for index
|
||||
n := 1
|
||||
for _, sect := range Segtext.Sections[1:] {
|
||||
if sect.Name == ".text" {
|
||||
symname := fmt.Sprintf("runtime.text.%d", n)
|
||||
ctxt.xdefine(symname, sym.STEXT, int64(sect.Vaddr))
|
||||
n++
|
||||
} else {
|
||||
if sect.Name != ".text" {
|
||||
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))
|
||||
|
@ -187,18 +187,18 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e
|
||||
continue
|
||||
}
|
||||
encodedPart := simplePart + "*"
|
||||
if v, ok := pieceMap[encodedPart]; ok {
|
||||
valid = true
|
||||
if n == 0 {
|
||||
if decv, ok := decode2231Enc(v); ok {
|
||||
buf.WriteString(decv)
|
||||
}
|
||||
} else {
|
||||
decv, _ := percentHexUnescape(v)
|
||||
v, ok := pieceMap[encodedPart]
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
valid = true
|
||||
if n == 0 {
|
||||
if decv, ok := decode2231Enc(v); ok {
|
||||
buf.WriteString(decv)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
decv, _ := percentHexUnescape(v)
|
||||
buf.WriteString(decv)
|
||||
}
|
||||
}
|
||||
if valid {
|
||||
|
@ -1074,15 +1074,14 @@ func (v Value) MapIndex(key Value) Value {
|
||||
typ := tt.elem
|
||||
fl := (v.flag | key.flag).ro()
|
||||
fl |= flag(typ.Kind())
|
||||
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 {
|
||||
if !ifaceIndir(typ) {
|
||||
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,
|
||||
|
@ -338,15 +338,14 @@ func (m *machine) onepass(i input, pos, ncap int) bool {
|
||||
if pos == 0 && syntax.EmptyOp(inst.Arg)&^flag == 0 &&
|
||||
len(m.re.prefix) > 0 && i.canCheckPrefix() {
|
||||
// Match requires literal prefix; fast search for it.
|
||||
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 {
|
||||
if !i.hasPrefix(m.re) {
|
||||
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 {
|
||||
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"
|
||||
for ; this < line1; this++ {
|
||||
line = b.lines[this]
|
||||
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 {
|
||||
if column >= len(line)-1 {
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user