Skip to content

Commit 340129e

Browse files
committed
all: join a few chained ifs
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í <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a125bdb commit 340129e

File tree

6 files changed

+41
-55
lines changed

6 files changed

+41
-55
lines changed

src/encoding/json/encode.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,15 @@ func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
392392
if t.Implements(marshalerType) {
393393
return marshalerEncoder
394394
}
395-
if t.Kind() != reflect.Ptr && allowAddr {
396-
if reflect.PtrTo(t).Implements(marshalerType) {
397-
return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
398-
}
395+
if t.Kind() != reflect.Ptr && allowAddr && reflect.PtrTo(t).Implements(marshalerType) {
396+
return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
399397
}
400398

401399
if t.Implements(textMarshalerType) {
402400
return textMarshalerEncoder
403401
}
404-
if t.Kind() != reflect.Ptr && allowAddr {
405-
if reflect.PtrTo(t).Implements(textMarshalerType) {
406-
return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
407-
}
402+
if t.Kind() != reflect.Ptr && allowAddr && reflect.PtrTo(t).Implements(textMarshalerType) {
403+
return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
408404
}
409405

410406
switch t.Kind() {

src/net/http/server.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,8 @@ func (cr *connReader) handleReadError(_ error) {
749749
// may be called from multiple goroutines.
750750
func (cr *connReader) closeNotify() {
751751
res, _ := cr.conn.curReq.Load().(*response)
752-
if res != nil {
753-
if atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
754-
res.closeNotifyCh <- true
755-
}
752+
if res != nil && atomic.CompareAndSwapInt32(&res.didCloseNotify, 0, 1) {
753+
res.closeNotifyCh <- true
756754
}
757755
}
758756

src/runtime/chan.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,8 @@ func (q *waitq) dequeue() *sudog {
729729
// We use a flag in the G struct to tell us when someone
730730
// else has won the race to signal this goroutine but the goroutine
731731
// hasn't removed itself from the queue yet.
732-
if sgp.isSelect {
733-
if !atomic.Cas(&sgp.g.selectDone, 0, 1) {
734-
continue
735-
}
732+
if sgp.isSelect && !atomic.Cas(&sgp.g.selectDone, 0, 1) {
733+
continue
736734
}
737735

738736
return sgp

src/runtime/signal_amd64x.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,19 @@ func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
4646

4747
// preparePanic sets up the stack to look like a call to sigpanic.
4848
func (c *sigctxt) preparePanic(sig uint32, gp *g) {
49-
if GOOS == "darwin" {
50-
// Work around Leopard bug that doesn't set FPE_INTDIV.
51-
// Look at instruction to see if it is a divide.
52-
// Not necessary in Snow Leopard (si_code will be != 0).
53-
if sig == _SIGFPE && gp.sigcode0 == 0 {
54-
pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
55-
i := 0
56-
if pc[i]&0xF0 == 0x40 { // 64-bit REX prefix
57-
i++
58-
} else if pc[i] == 0x66 { // 16-bit instruction prefix
59-
i++
60-
}
61-
if pc[i] == 0xF6 || pc[i] == 0xF7 {
62-
gp.sigcode0 = _FPE_INTDIV
63-
}
49+
// Work around Leopard bug that doesn't set FPE_INTDIV.
50+
// Look at instruction to see if it is a divide.
51+
// Not necessary in Snow Leopard (si_code will be != 0).
52+
if GOOS == "darwin" && sig == _SIGFPE && gp.sigcode0 == 0 {
53+
pc := (*[4]byte)(unsafe.Pointer(gp.sigpc))
54+
i := 0
55+
if pc[i]&0xF0 == 0x40 { // 64-bit REX prefix
56+
i++
57+
} else if pc[i] == 0x66 { // 16-bit instruction prefix
58+
i++
59+
}
60+
if pc[i] == 0xF6 || pc[i] == 0xF7 {
61+
gp.sigcode0 = _FPE_INTDIV
6462
}
6563
}
6664

src/runtime/signal_unix.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,14 @@ func raisebadsignal(sig uint32, c *sigctxt) {
503503

504504
//go:nosplit
505505
func crash() {
506-
if GOOS == "darwin" {
507-
// OS X core dumps are linear dumps of the mapped memory,
508-
// from the first virtual byte to the last, with zeros in the gaps.
509-
// Because of the way we arrange the address space on 64-bit systems,
510-
// this means the OS X core file will be >128 GB and even on a zippy
511-
// workstation can take OS X well over an hour to write (uninterruptible).
512-
// Save users from making that mistake.
513-
if GOARCH == "amd64" {
514-
return
515-
}
506+
// OS X core dumps are linear dumps of the mapped memory,
507+
// from the first virtual byte to the last, with zeros in the gaps.
508+
// Because of the way we arrange the address space on 64-bit systems,
509+
// this means the OS X core file will be >128 GB and even on a zippy
510+
// workstation can take OS X well over an hour to write (uninterruptible).
511+
// Save users from making that mistake.
512+
if GOOS == "darwin" && GOARCH == "amd64" {
513+
return
516514
}
517515

518516
dieFromSignal(_SIGABRT)

src/testing/testing.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,20 +1303,18 @@ func toOutputDir(path string) string {
13031303
if *outputDir == "" || path == "" {
13041304
return path
13051305
}
1306-
if runtime.GOOS == "windows" {
1307-
// On Windows, it's clumsy, but we can be almost always correct
1308-
// by just looking for a drive letter and a colon.
1309-
// Absolute paths always have a drive letter (ignoring UNC).
1310-
// Problem: if path == "C:A" and outputdir == "C:\Go" it's unclear
1311-
// what to do, but even then path/filepath doesn't help.
1312-
// TODO: Worth doing better? Probably not, because we're here only
1313-
// under the management of go test.
1314-
if len(path) >= 2 {
1315-
letter, colon := path[0], path[1]
1316-
if ('a' <= letter && letter <= 'z' || 'A' <= letter && letter <= 'Z') && colon == ':' {
1317-
// If path starts with a drive letter we're stuck with it regardless.
1318-
return path
1319-
}
1306+
// On Windows, it's clumsy, but we can be almost always correct
1307+
// by just looking for a drive letter and a colon.
1308+
// Absolute paths always have a drive letter (ignoring UNC).
1309+
// Problem: if path == "C:A" and outputdir == "C:\Go" it's unclear
1310+
// what to do, but even then path/filepath doesn't help.
1311+
// TODO: Worth doing better? Probably not, because we're here only
1312+
// under the management of go test.
1313+
if runtime.GOOS == "windows" && len(path) >= 2 {
1314+
letter, colon := path[0], path[1]
1315+
if ('a' <= letter && letter <= 'z' || 'A' <= letter && letter <= 'Z') && colon == ':' {
1316+
// If path starts with a drive letter we're stuck with it regardless.
1317+
return path
13201318
}
13211319
}
13221320
if os.IsPathSeparator(path[0]) {

0 commit comments

Comments
 (0)