Commit fbc8973a authored by Daniel Martí's avatar Daniel Martí

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: default avatarIan Lance Taylor <iant@golang.org>
parent 305fd917
...@@ -37,11 +37,9 @@ func (w StreamWriter) Write(src []byte) (n int, err error) { ...@@ -37,11 +37,9 @@ func (w StreamWriter) Write(src []byte) (n int, err error) {
c := make([]byte, len(src)) c := make([]byte, len(src))
w.S.XORKeyStream(c, src) w.S.XORKeyStream(c, src)
n, err = w.W.Write(c) n, err = w.W.Write(c)
if n != len(src) { if n != len(src) && err == nil { // should never happen
if err == nil { // should never happen
err = io.ErrShortWrite err = io.ErrShortWrite
} }
}
return return
} }
......
...@@ -99,11 +99,9 @@ func (dec *Decoder) readMessage(nbytes int) { ...@@ -99,11 +99,9 @@ func (dec *Decoder) readMessage(nbytes int) {
// Read the data // Read the data
dec.buf.Size(nbytes) dec.buf.Size(nbytes)
_, dec.err = io.ReadFull(dec.r, dec.buf.Bytes()) _, dec.err = io.ReadFull(dec.r, dec.buf.Bytes())
if dec.err != nil {
if dec.err == io.EOF { if dec.err == io.EOF {
dec.err = io.ErrUnexpectedEOF dec.err = io.ErrUnexpectedEOF
} }
}
} }
// toInt turns an encoded uint64 into an int, according to the marshaling rules. // toInt turns an encoded uint64 into an int, according to the marshaling rules.
......
...@@ -530,11 +530,9 @@ func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done b ...@@ -530,11 +530,9 @@ func checkPreconditions(w ResponseWriter, r *Request, modtime time.Time) (done b
} }
rangeHeader = r.Header.get("Range") rangeHeader = r.Header.get("Range")
if rangeHeader != "" { if rangeHeader != "" && checkIfRange(w, r, modtime) == condFalse {
if checkIfRange(w, r, modtime) == condFalse {
rangeHeader = "" rangeHeader = ""
} }
}
return false, rangeHeader return false, rangeHeader
} }
......
...@@ -953,14 +953,12 @@ func (u *URL) ResolveReference(ref *URL) *URL { ...@@ -953,14 +953,12 @@ func (u *URL) ResolveReference(ref *URL) *URL {
url.Path = "" url.Path = ""
return &url return &url
} }
if ref.Path == "" { if ref.Path == "" && ref.RawQuery == "" {
if ref.RawQuery == "" {
url.RawQuery = u.RawQuery url.RawQuery = u.RawQuery
if ref.Fragment == "" { if ref.Fragment == "" {
url.Fragment = u.Fragment url.Fragment = u.Fragment
} }
} }
}
// The "abs_path" or "rel_path" cases. // The "abs_path" or "rel_path" cases.
url.Host = u.Host url.Host = u.Host
url.User = u.User url.User = u.User
......
...@@ -580,11 +580,9 @@ func cgoCheckUnknownPointer(p unsafe.Pointer, msg string) (base, i uintptr) { ...@@ -580,11 +580,9 @@ func cgoCheckUnknownPointer(p unsafe.Pointer, msg string) (base, i uintptr) {
// No more possible pointers. // No more possible pointers.
break break
} }
if hbits.isPointer() { if hbits.isPointer() && cgoIsGoPointer(*(*unsafe.Pointer)(unsafe.Pointer(base + i))) {
if cgoIsGoPointer(*(*unsafe.Pointer)(unsafe.Pointer(base + i))) {
panic(errorString(msg)) panic(errorString(msg))
} }
}
hbits = hbits.next() hbits = hbits.next()
} }
......
...@@ -3568,14 +3568,12 @@ func procresize(nprocs int32) *p { ...@@ -3568,14 +3568,12 @@ func procresize(nprocs int32) *p {
// free unused P's // free unused P's
for i := nprocs; i < old; i++ { for i := nprocs; i < old; i++ {
p := allp[i] p := allp[i]
if trace.enabled { if trace.enabled && p == getg().m.p.ptr() {
if p == getg().m.p.ptr() {
// moving to p[0], pretend that we were descheduled // moving to p[0], pretend that we were descheduled
// and then scheduled again to keep the trace sane. // and then scheduled again to keep the trace sane.
traceGoSched() traceGoSched()
traceProcStop(p) traceProcStop(p)
} }
}
// move all runnable goroutines to the global queue // move all runnable goroutines to the global queue
for p.runqhead != p.runqtail { for p.runqhead != p.runqtail {
// pop from tail of local queue // pop from tail of local queue
......
...@@ -457,11 +457,9 @@ loop: ...@@ -457,11 +457,9 @@ loop:
print("wait-return: sel=", sel, " c=", c, " cas=", cas, " kind=", cas.kind, "\n") print("wait-return: sel=", sel, " c=", c, " cas=", cas, " kind=", cas.kind, "\n")
} }
if cas.kind == caseRecv { if cas.kind == caseRecv && cas.receivedp != nil {
if cas.receivedp != nil {
*cas.receivedp = true *cas.receivedp = true
} }
}
if raceenabled { if raceenabled {
if cas.kind == caseRecv && cas.elem != nil { if cas.kind == caseRecv && cas.elem != nil {
......
...@@ -63,14 +63,12 @@ func (wg *WaitGroup) Add(delta int) { ...@@ -63,14 +63,12 @@ func (wg *WaitGroup) Add(delta int) {
state := atomic.AddUint64(statep, uint64(delta)<<32) state := atomic.AddUint64(statep, uint64(delta)<<32)
v := int32(state >> 32) v := int32(state >> 32)
w := uint32(state) w := uint32(state)
if race.Enabled { if race.Enabled && delta > 0 && v == int32(delta) {
if delta > 0 && v == int32(delta) {
// The first increment must be synchronized with Wait. // The first increment must be synchronized with Wait.
// Need to model this as a read, because there can be // Need to model this as a read, because there can be
// several concurrent wg.counter transitions from 0. // several concurrent wg.counter transitions from 0.
race.Read(unsafe.Pointer(&wg.sema)) race.Read(unsafe.Pointer(&wg.sema))
} }
}
if v < 0 { if v < 0 {
panic("sync: negative WaitGroup counter") panic("sync: negative WaitGroup counter")
} }
......
...@@ -281,11 +281,10 @@ func (l *lexer) atRightDelim() (delim, trimSpaces bool) { ...@@ -281,11 +281,10 @@ func (l *lexer) atRightDelim() (delim, trimSpaces bool) {
return true, false return true, false
} }
// The right delim might have the marker before. // The right delim might have the marker before.
if strings.HasPrefix(l.input[l.pos:], rightTrimMarker) { if strings.HasPrefix(l.input[l.pos:], rightTrimMarker) &&
if strings.HasPrefix(l.input[l.pos+trimMarkerLen:], l.rightDelim) { strings.HasPrefix(l.input[l.pos+trimMarkerLen:], l.rightDelim) {
return true, true return true, true
} }
}
return false, false return false, false
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment