all: join some chained ifs to unindent code

Found with mvdan.cc/unindent. It skipped the cases where parentheses
would need to be added, where comments would have to be moved elsewhere,
or where actions and simple logic would mix.

One of them was of the form "err != nil && err == io.EOF", so the first
part was removed.

Change-Id: Ie504c2b03a2c87d10ecbca1b9270069be1171b91
Reviewed-on: https://go-review.googlesource.com/57690
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Daniel Martí 2017-08-21 22:23:14 +02:00
parent 305fd9179d
commit fbc8973a6b
9 changed files with 27 additions and 44 deletions

View File

@ -37,10 +37,8 @@ func (w StreamWriter) Write(src []byte) (n int, err error) {
c := make([]byte, len(src))
w.S.XORKeyStream(c, src)
n, err = w.W.Write(c)
if n != len(src) {
if err == nil { // should never happen
err = io.ErrShortWrite
}
if n != len(src) && err == nil { // should never happen
err = io.ErrShortWrite
}
return
}

View File

@ -99,10 +99,8 @@ func (dec *Decoder) readMessage(nbytes int) {
// Read the data
dec.buf.Size(nbytes)
_, dec.err = io.ReadFull(dec.r, dec.buf.Bytes())
if dec.err != nil {
if dec.err == io.EOF {
dec.err = io.ErrUnexpectedEOF
}
if dec.err == io.EOF {
dec.err = io.ErrUnexpectedEOF
}
}

View File

@ -530,10 +530,8 @@ func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done b
}
rangeHeader = r.Header.get("Range")
if rangeHeader != "" {
if checkIfRange(w, r, modtime) == condFalse {
rangeHeader = ""
}
if rangeHeader != "" && checkIfRange(w, r, modtime) == condFalse {
rangeHeader = ""
}
return false, rangeHeader
}

View File

@ -953,12 +953,10 @@ func (u *URL) ResolveReference(ref *URL) *URL {
url.Path = ""
return &url
}
if ref.Path == "" {
if ref.RawQuery == "" {
url.RawQuery = u.RawQuery
if ref.Fragment == "" {
url.Fragment = u.Fragment
}
if ref.Path == "" && ref.RawQuery == "" {
url.RawQuery = u.RawQuery
if ref.Fragment == "" {
url.Fragment = u.Fragment
}
}
// The "abs_path" or "rel_path" cases.

View File

@ -580,10 +580,8 @@ func cgoCheckUnknownPointer(p unsafe.Pointer, msg string) (base, i uintptr) {
// No more possible pointers.
break
}
if hbits.isPointer() {
if cgoIsGoPointer(*(*unsafe.Pointer)(unsafe.Pointer(base + i))) {
panic(errorString(msg))
}
if hbits.isPointer() && cgoIsGoPointer(*(*unsafe.Pointer)(unsafe.Pointer(base + i))) {
panic(errorString(msg))
}
hbits = hbits.next()
}

View File

@ -3568,13 +3568,11 @@ func procresize(nprocs int32) *p {
// free unused P's
for i := nprocs; i < old; i++ {
p := allp[i]
if trace.enabled {
if p == getg().m.p.ptr() {
// moving to p[0], pretend that we were descheduled
// and then scheduled again to keep the trace sane.
traceGoSched()
traceProcStop(p)
}
if trace.enabled && p == getg().m.p.ptr() {
// moving to p[0], pretend that we were descheduled
// and then scheduled again to keep the trace sane.
traceGoSched()
traceProcStop(p)
}
// move all runnable goroutines to the global queue
for p.runqhead != p.runqtail {

View File

@ -457,10 +457,8 @@ loop:
print("wait-return: sel=", sel, " c=", c, " cas=", cas, " kind=", cas.kind, "\n")
}
if cas.kind == caseRecv {
if cas.receivedp != nil {
*cas.receivedp = true
}
if cas.kind == caseRecv && cas.receivedp != nil {
*cas.receivedp = true
}
if raceenabled {

View File

@ -63,13 +63,11 @@ func (wg *WaitGroup) Add(delta int) {
state := atomic.AddUint64(statep, uint64(delta)<<32)
v := int32(state >> 32)
w := uint32(state)
if race.Enabled {
if delta > 0 && v == int32(delta) {
// The first increment must be synchronized with Wait.
// Need to model this as a read, because there can be
// several concurrent wg.counter transitions from 0.
race.Read(unsafe.Pointer(&wg.sema))
}
if race.Enabled && delta > 0 && v == int32(delta) {
// The first increment must be synchronized with Wait.
// Need to model this as a read, because there can be
// several concurrent wg.counter transitions from 0.
race.Read(unsafe.Pointer(&wg.sema))
}
if v < 0 {
panic("sync: negative WaitGroup counter")

View File

@ -281,10 +281,9 @@ func (l *lexer) atRightDelim() (delim, trimSpaces bool) {
return true, false
}
// The right delim might have the marker before.
if strings.HasPrefix(l.input[l.pos:], rightTrimMarker) {
if strings.HasPrefix(l.input[l.pos+trimMarkerLen:], l.rightDelim) {
return true, true
}
if strings.HasPrefix(l.input[l.pos:], rightTrimMarker) &&
strings.HasPrefix(l.input[l.pos+trimMarkerLen:], l.rightDelim) {
return true, true
}
return false, false
}