]> Cypherpunks repositories - gostls13.git/commitdiff
all: join a few chained ifs
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 5 Mar 2019 20:21:17 +0000 (20:21 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 5 Mar 2019 20:31:32 +0000 (20:31 +0000)
I had been finding these over a year or so, but none were big enough
changes to warrant CLs. They're a handful now, so clean them all up in a
single commit.

The smaller bodies get a bit simpler, but most importantly, the larger
bodies get unindented.

Change-Id: I5707a6fee27d4c9ff9efd3d363af575d7a4bf2aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/165340
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/encoding/json/encode.go
src/net/http/server.go
src/runtime/chan.go
src/runtime/signal_amd64x.go
src/runtime/signal_unix.go
src/testing/testing.go

index dea63f1850fef444dc8a6a3490c6d3983c97afba..de6d2632f42a4fc21b5e1d38dc069f575494cb45 100644 (file)
@@ -392,19 +392,15 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
        if t.Implements(marshalerType) {
                return marshalerEncoder
        }
-       if t.Kind() != reflect.Ptr && allowAddr {
-               if reflect.PtrTo(t).Implements(marshalerType) {
-                       return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
-               }
+       if t.Kind() != reflect.Ptr && allowAddr && reflect.PtrTo(t).Implements(marshalerType) {
+               return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
        }
 
        if t.Implements(textMarshalerType) {
                return textMarshalerEncoder
        }
-       if t.Kind() != reflect.Ptr && allowAddr {
-               if reflect.PtrTo(t).Implements(textMarshalerType) {
-                       return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
-               }
+       if t.Kind() != reflect.Ptr && allowAddr && reflect.PtrTo(t).Implements(textMarshalerType) {
+               return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
        }
 
        switch t.Kind() {
index 9ae0bbff14920c536d40730b7c4a27e830b19fce..a19934e469194fb5401ccb97ba091a76f05b3efe 100644 (file)
@@ -749,10 +749,8 @@ func (cr *connReader) handleReadError(_ error) {
 // may be called from multiple goroutines.
 func (cr *connReader) closeNotify() {
        res, _ := cr.conn.curReq.Load().(*response)
-       if res != nil {
-               if atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
-                       res.closeNotifyCh <- true
-               }
+       if res != nil && atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
+               res.closeNotifyCh <- true
        }
 }
 
index 8662f00e132890264f6bb94251b64c9337748309..389bf799e2e469f3e527965f4204e8d4f52190ed 100644 (file)
@@ -729,10 +729,8 @@ func (q *waitq) dequeue() *sudog {
                // We use a flag in the G struct to tell us when someone
                // else has won the race to signal this goroutine but the goroutine
                // hasn't removed itself from the queue yet.
-               if sgp.isSelect {
-                       if !atomic.Cas(&sgp.g.selectDone, 0, 1) {
-                               continue
-                       }
+               if sgp.isSelect && !atomic.Cas(&sgp.g.selectDone, 0, 1) {
+                       continue
                }
 
                return sgp
index 823fd295ae7ce2b13b78167fc0923f745ff56fd2..9d59e262de3b8f49745aef28ec91550af4bd804d 100644 (file)
@@ -46,21 +46,19 @@ func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
 
 // preparePanic sets up the stack to look like a call to sigpanic.
 func (c *sigctxt) preparePanic(sig uint32, gp *g) {
-       if GOOS == "darwin" {
-               // Work around Leopard bug that doesn't set FPE_INTDIV.
-               // Look at instruction to see if it is a divide.
-               // Not necessary in Snow Leopard (si_code will be != 0).
-               if sig == _SIGFPE && gp.sigcode0 == 0 {
-                       pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
-                       i := 0
-                       if pc[i]&0xF0 == 0x40 { // 64-bit REX prefix
-                               i++
-                       } else if pc[i] == 0x66 { // 16-bit instruction prefix
-                               i++
-                       }
-                       if pc[i] == 0xF6 || pc[i] == 0xF7 {
-                               gp.sigcode0 = _FPE_INTDIV
-                       }
+       // Work around Leopard bug that doesn't set FPE_INTDIV.
+       // Look at instruction to see if it is a divide.
+       // Not necessary in Snow Leopard (si_code will be != 0).
+       if GOOS == "darwin" && sig == _SIGFPE && gp.sigcode0 == 0 {
+               pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
+               i := 0
+               if pc[i]&0xF0 == 0x40 { // 64-bit REX prefix
+                       i++
+               } else if pc[i] == 0x66 { // 16-bit instruction prefix
+                       i++
+               }
+               if pc[i] == 0xF6 || pc[i] == 0xF7 {
+                       gp.sigcode0 = _FPE_INTDIV
                }
        }
 
index 15f1799801921d2bb83f628b360beffaff5b66fa..8814f7836dc1aef0fd78c19e751a97d1a752ce88 100644 (file)
@@ -503,16 +503,14 @@ func raisebadsignal(sig uint32, c *sigctxt) {
 
 //go:nosplit
 func crash() {
-       if GOOS == "darwin" {
-               // OS X core dumps are linear dumps of the mapped memory,
-               // from the first virtual byte to the last, with zeros in the gaps.
-               // Because of the way we arrange the address space on 64-bit systems,
-               // this means the OS X core file will be >128 GB and even on a zippy
-               // workstation can take OS X well over an hour to write (uninterruptible).
-               // Save users from making that mistake.
-               if GOARCH == "amd64" {
-                       return
-               }
+       // OS X core dumps are linear dumps of the mapped memory,
+       // from the first virtual byte to the last, with zeros in the gaps.
+       // Because of the way we arrange the address space on 64-bit systems,
+       // this means the OS X core file will be >128 GB and even on a zippy
+       // workstation can take OS X well over an hour to write (uninterruptible).
+       // Save users from making that mistake.
+       if GOOS == "darwin" && GOARCH == "amd64" {
+               return
        }
 
        dieFromSignal(_SIGABRT)
index 79dcf76908aa190caeef3400767762336ba41259..8cbb4318fca26942e5ff96c4f7c824d847eefc40 100644 (file)
@@ -1303,20 +1303,18 @@ func toOutputDir(path string) string {
        if *outputDir == "" || path == "" {
                return path
        }
-       if runtime.GOOS == "windows" {
-               // On Windows, it's clumsy, but we can be almost always correct
-               // by just looking for a drive letter and a colon.
-               // Absolute paths always have a drive letter (ignoring UNC).
-               // Problem: if path == "C:A" and outputdir == "C:\Go" it's unclear
-               // what to do, but even then path/filepath doesn't help.
-               // TODO: Worth doing better? Probably not, because we're here only
-               // under the management of go test.
-               if len(path) >= 2 {
-                       letter, colon := path[0], path[1]
-                       if ('a' <= letter && letter <= 'z' || 'A' <= letter && letter <= 'Z') && colon == ':' {
-                               // If path starts with a drive letter we're stuck with it regardless.
-                               return path
-                       }
+       // On Windows, it's clumsy, but we can be almost always correct
+       // by just looking for a drive letter and a colon.
+       // Absolute paths always have a drive letter (ignoring UNC).
+       // Problem: if path == "C:A" and outputdir == "C:\Go" it's unclear
+       // what to do, but even then path/filepath doesn't help.
+       // TODO: Worth doing better? Probably not, because we're here only
+       // under the management of go test.
+       if runtime.GOOS == "windows" && len(path) >= 2 {
+               letter, colon := path[0], path[1]
+               if ('a' <= letter && letter <= 'z' || 'A' <= letter && letter <= 'Z') && colon == ':' {
+                       // If path starts with a drive letter we're stuck with it regardless.
+                       return path
                }
        }
        if os.IsPathSeparator(path[0]) {