Commit 59413d34 authored by Daniel Martí's avatar Daniel Martí

all: unindent some big chunks of code

Found with mvdan.cc/unindent. Prioritized the ones with the biggest wins
for now.

Change-Id: I2b032e45cdd559fc9ed5b1ee4c4de42c4c92e07b
Reviewed-on: https://go-review.googlesource.com/56470
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent b73d46de
...@@ -285,7 +285,12 @@ func Fields(s []byte) [][]byte { ...@@ -285,7 +285,12 @@ func Fields(s []byte) [][]byte {
wasSpace = isSpace wasSpace = isSpace
} }
if setBits < utf8.RuneSelf { // ASCII fast path if setBits >= utf8.RuneSelf {
// Some runes in the input slice are not ASCII.
return FieldsFunc(s, unicode.IsSpace)
}
// ASCII fast path
a := make([][]byte, n) a := make([][]byte, n)
na := 0 na := 0
fieldStart := 0 fieldStart := 0
...@@ -313,10 +318,6 @@ func Fields(s []byte) [][]byte { ...@@ -313,10 +318,6 @@ func Fields(s []byte) [][]byte {
a[na] = s[fieldStart:] a[na] = s[fieldStart:]
} }
return a return a
}
// Some runes in the input slice are not ASCII.
return FieldsFunc(s, unicode.IsSpace)
} }
// FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points. // FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points.
......
...@@ -514,7 +514,9 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off ...@@ -514,7 +514,9 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
var lastFieldType *Type var lastFieldType *Type
var lastFieldBitOffset int64 var lastFieldBitOffset int64
for kid := next(); kid != nil; kid = next() { for kid := next(); kid != nil; kid = next() {
if kid.Tag == TagMember { if kid.Tag != TagMember {
continue
}
f := new(StructField) f := new(StructField)
if f.Type = typeOf(kid); err != nil { if f.Type = typeOf(kid); err != nil {
goto Error goto Error
...@@ -556,7 +558,6 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off ...@@ -556,7 +558,6 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
lastFieldType = &f.Type lastFieldType = &f.Type
lastFieldBitOffset = bito lastFieldBitOffset = bito
} }
}
if t.Kind != "union" { if t.Kind != "union" {
b, ok := e.Val(AttrByteSize).(int64) b, ok := e.Val(AttrByteSize).(int64)
if ok && b*8 == lastFieldBitOffset { if ok && b*8 == lastFieldBitOffset {
......
...@@ -1195,7 +1195,9 @@ func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binary ...@@ -1195,7 +1195,9 @@ func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binary
p = p[len(p):] p = p[len(p):]
} }
line = bytes.TrimSpace(line) line = bytes.TrimSpace(line)
if bytes.HasPrefix(line, slashslash) { if !bytes.HasPrefix(line, slashslash) {
continue
}
if bytes.Equal(line, binaryOnlyComment) { if bytes.Equal(line, binaryOnlyComment) {
sawBinaryOnly = true sawBinaryOnly = true
} }
...@@ -1216,7 +1218,6 @@ func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binary ...@@ -1216,7 +1218,6 @@ func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binary
} }
} }
} }
}
if binaryOnly != nil && sawBinaryOnly { if binaryOnly != nil && sawBinaryOnly {
*binaryOnly = true *binaryOnly = true
......
...@@ -134,7 +134,10 @@ type getter func(x *operand, i int) ...@@ -134,7 +134,10 @@ type getter func(x *operand, i int)
// the incoming getter with that i. // the incoming getter with that i.
// //
func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) { func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) {
if n == 1 { if n != 1 {
// zero or multiple values
return get, n, false
}
// possibly result of an n-valued function call or comma,ok value // possibly result of an n-valued function call or comma,ok value
var x0 operand var x0 operand
get(&x0, 0) get(&x0, 0)
...@@ -171,10 +174,6 @@ func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) { ...@@ -171,10 +174,6 @@ func unpack(get getter, n int, allowCommaOk bool) (getter, int, bool) {
} }
*x = x0 *x = x0
}, 1, false }, 1, false
}
// zero or multiple values
return get, n, false
} }
// arguments checks argument passing for the call with the given signature. // arguments checks argument passing for the call with the given signature.
......
...@@ -205,7 +205,9 @@ func expm1(x float64) float64 { ...@@ -205,7 +205,9 @@ func expm1(x float64) float64 {
r1 := 1 + hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))) r1 := 1 + hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))))
t := 3 - r1*hfx t := 3 - r1*hfx
e := hxs * ((r1 - t) / (6.0 - x*t)) e := hxs * ((r1 - t) / (6.0 - x*t))
if k != 0 { if k == 0 {
return x - (x*e - hxs) // c is 0
}
e = (x*(e-c) - c) e = (x*(e-c) - c)
e -= hxs e -= hxs
switch { switch {
...@@ -227,11 +229,9 @@ func expm1(x float64) float64 { ...@@ -227,11 +229,9 @@ func expm1(x float64) float64 {
y = Float64frombits(Float64bits(y) + uint64(k)<<52) // add k to y's exponent y = Float64frombits(Float64bits(y) + uint64(k)<<52) // add k to y's exponent
return y return y
} }
t := Float64frombits(uint64(0x3ff-k) << 52) // 2**-k t = Float64frombits(uint64(0x3ff-k) << 52) // 2**-k
y := x - (e + t) y := x - (e + t)
y++ y++
y = Float64frombits(Float64bits(y) + uint64(k)<<52) // add k to y's exponent y = Float64frombits(Float64bits(y) + uint64(k)<<52) // add k to y's exponent
return y return y
}
return x - (x*e - hxs) // c is 0
} }
...@@ -1129,7 +1129,9 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr { ...@@ -1129,7 +1129,9 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr {
var sumreleased uintptr var sumreleased uintptr
for s := list.first; s != nil; s = s.next { for s := list.first; s != nil; s = s.next {
if (now-uint64(s.unusedsince)) > limit && s.npreleased != s.npages { if (now-uint64(s.unusedsince)) <= limit || s.npreleased == s.npages {
continue
}
start := s.base() start := s.base()
end := start + s.npages<<_PageShift end := start + s.npages<<_PageShift
if physPageSize > _PageSize { if physPageSize > _PageSize {
...@@ -1157,7 +1159,6 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr { ...@@ -1157,7 +1159,6 @@ func scavengelist(list *mSpanList, now, limit uint64) uintptr {
s.npreleased = len >> _PageShift s.npreleased = len >> _PageShift
sysUnused(unsafe.Pointer(start), len) sysUnused(unsafe.Pointer(start), len)
} }
}
return sumreleased return sumreleased
} }
......
...@@ -208,7 +208,9 @@ func sysargs(argc int32, argv **byte) { ...@@ -208,7 +208,9 @@ func sysargs(argc int32, argv **byte) {
// now argv+n is auxv // now argv+n is auxv
auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize)) auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
if sysauxv(auxv[:]) == 0 { if sysauxv(auxv[:]) != 0 {
return
}
// In some situations we don't get a loader-provided // In some situations we don't get a loader-provided
// auxv, such as when loaded as a library on Android. // auxv, such as when loaded as a library on Android.
// Fall back to /proc/self/auxv. // Fall back to /proc/self/auxv.
...@@ -237,7 +239,7 @@ func sysargs(argc int32, argv **byte) { ...@@ -237,7 +239,7 @@ func sysargs(argc int32, argv **byte) {
return return
} }
var buf [128]uintptr var buf [128]uintptr
n := read(fd, noescape(unsafe.Pointer(&buf[0])), int32(unsafe.Sizeof(buf))) n = read(fd, noescape(unsafe.Pointer(&buf[0])), int32(unsafe.Sizeof(buf)))
closefd(fd) closefd(fd)
if n < 0 { if n < 0 {
return return
...@@ -246,7 +248,6 @@ func sysargs(argc int32, argv **byte) { ...@@ -246,7 +248,6 @@ func sysargs(argc int32, argv **byte) {
// the whole file. // the whole file.
buf[len(buf)-2] = _AT_NULL buf[len(buf)-2] = _AT_NULL
sysauxv(buf[:]) sysauxv(buf[:])
}
} }
func sysauxv(auxv []uintptr) int { func sysauxv(auxv []uintptr) int {
......
...@@ -244,7 +244,9 @@ func freedefer(d *_defer) { ...@@ -244,7 +244,9 @@ func freedefer(d *_defer) {
freedeferfn() freedeferfn()
} }
sc := deferclass(uintptr(d.siz)) sc := deferclass(uintptr(d.siz))
if sc < uintptr(len(p{}.deferpool)) { if sc >= uintptr(len(p{}.deferpool)) {
return
}
pp := getg().m.p.ptr() pp := getg().m.p.ptr()
if len(pp.deferpool[sc]) == cap(pp.deferpool[sc]) { if len(pp.deferpool[sc]) == cap(pp.deferpool[sc]) {
// Transfer half of local cache to the central cache. // Transfer half of local cache to the central cache.
...@@ -273,7 +275,6 @@ func freedefer(d *_defer) { ...@@ -273,7 +275,6 @@ func freedefer(d *_defer) {
} }
*d = _defer{} *d = _defer{}
pp.deferpool[sc] = append(pp.deferpool[sc], d) pp.deferpool[sc] = append(pp.deferpool[sc], d)
}
} }
// Separate function so that it can split stack. // Separate function so that it can split stack.
......
...@@ -578,7 +578,9 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f ...@@ -578,7 +578,9 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f
if stackDebug >= 4 { if stackDebug >= 4 {
print(" ", add(scanp, i*sys.PtrSize), ":", ptrnames[ptrbit(&bv, i)], ":", hex(*(*uintptr)(add(scanp, i*sys.PtrSize))), " # ", i, " ", bv.bytedata[i/8], "\n") print(" ", add(scanp, i*sys.PtrSize), ":", ptrnames[ptrbit(&bv, i)], ":", hex(*(*uintptr)(add(scanp, i*sys.PtrSize))), " # ", i, " ", bv.bytedata[i/8], "\n")
} }
if ptrbit(&bv, i) == 1 { if ptrbit(&bv, i) != 1 {
continue
}
pp := (*uintptr)(add(scanp, i*sys.PtrSize)) pp := (*uintptr)(add(scanp, i*sys.PtrSize))
retry: retry:
p := *pp p := *pp
...@@ -603,7 +605,6 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f ...@@ -603,7 +605,6 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f
} }
} }
} }
}
} }
// Note: the argument/return area is adjusted by the callee. // Note: the argument/return area is adjusted by the callee.
......
...@@ -333,7 +333,9 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) { ...@@ -333,7 +333,9 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) {
for this := line0; this < line1; this++ { for this := line0; this < line1; this++ {
line := b.lines[this] line := b.lines[this]
if column < len(line)-1 { if column >= len(line)-1 {
continue
}
// cell exists in this column => this line // cell exists in this column => this line
// has more cells than the previous line // has more cells than the previous line
// (the last cell per line is ignored because cells are // (the last cell per line is ignored because cells are
...@@ -379,7 +381,6 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) { ...@@ -379,7 +381,6 @@ func (b *Writer) format(pos0 int, line0, line1 int) (pos int) {
b.widths = b.widths[0 : len(b.widths)-1] // pop width b.widths = b.widths[0 : len(b.widths)-1] // pop width
line0 = this line0 = this
} }
}
// print unprinted lines until end // print unprinted lines until end
return b.writeLines(pos, line0, line1) return b.writeLines(pos, line0, line1)
......
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