]> Cypherpunks repositories - gostls13.git/commitdiff
all: unindent some if bodies by exiting early
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 28 Oct 2017 16:35:27 +0000 (17:35 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 31 Oct 2017 20:07:46 +0000 (20:07 +0000)
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>
src/cmd/compile/internal/gc/bexport.go
src/cmd/link/internal/ld/data.go
src/mime/mediatype.go
src/reflect/value.go
src/regexp/exec.go
src/text/tabwriter/tabwriter.go

index 8b1f8a1b806e00c2904e45fe6b9d10a3b7128824..032fe73a9e52bc470fc0815910c211cc6b3756e4 100644 (file)
@@ -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 {
index 92ca33972aad45b792b2aaeb38763af90861c3ca..d3884f3515ecee01ea1cb6df169d09ab0804e07b 100644 (file)
@@ -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))
index b8a83d6f79c1a7750768b6c6d49a2b1678bc30db..426d417da230e2599201853d1a4a9d143bd9902c 100644 (file)
@@ -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 {
index d3b03e9b028c8f8d96a845ff2b906f3f958f6dd4..0184e6820eccfc4a990cd7ba73df62e9de1e5f08 100644 (file)
@@ -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,
index ea5b1361cb24fac8f351c9d8f8b5c9efbb7765f6..84cb3e6fa510a0a505d16722429f1085e917e15c 100644 (file)
@@ -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]
index c17cef8bd9b3684231af6dd1dab4acce58c9c819..ae6c7a29493e2b0432bcbf8f3772ce670a29aa81 100644 (file)
@@ -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