diff options
| author | Daniel Martí <mvdan@mvdan.cc> | 2017-08-17 15:51:35 +0100 |
|---|---|---|
| committer | Daniel Martí <mvdan@mvdan.cc> | 2017-08-18 06:59:48 +0000 |
| commit | 59413d34c92cf5ce9b0e70e7105ed73a24849b3e (patch) | |
| tree | 858c93ecabecd2f768046e33ea11b3530b74f78d /src/bytes/bytes.go | |
| parent | b73d46de36e937819f34a37a46af73eb435246aa (diff) | |
| download | go-59413d34c92cf5ce9b0e70e7105ed73a24849b3e.tar.xz | |
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: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/bytes/bytes.go')
| -rw-r--r-- | src/bytes/bytes.go | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index 457e149410..446026233e 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -285,38 +285,39 @@ func Fields(s []byte) [][]byte { wasSpace = isSpace } - if setBits < utf8.RuneSelf { // ASCII fast path - a := make([][]byte, n) - na := 0 - fieldStart := 0 - i := 0 - // Skip spaces in the front of the input. - for i < len(s) && asciiSpace[s[i]] != 0 { + 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) + na := 0 + fieldStart := 0 + i := 0 + // Skip spaces in the front of the input. + for i < len(s) && asciiSpace[s[i]] != 0 { + i++ + } + fieldStart = i + for i < len(s) { + if asciiSpace[s[i]] == 0 { i++ + continue } - fieldStart = i - for i < len(s) { - if asciiSpace[s[i]] == 0 { - i++ - continue - } - a[na] = s[fieldStart:i] - na++ + a[na] = s[fieldStart:i] + na++ + i++ + // Skip spaces in between fields. + for i < len(s) && asciiSpace[s[i]] != 0 { i++ - // Skip spaces in between fields. - for i < len(s) && asciiSpace[s[i]] != 0 { - i++ - } - fieldStart = i } - if fieldStart < len(s) { // Last field might end at EOF. - a[na] = s[fieldStart:] - } - return a + fieldStart = i } - - // Some runes in the input slice are not ASCII. - return FieldsFunc(s, unicode.IsSpace) + if fieldStart < len(s) { // Last field might end at EOF. + a[na] = s[fieldStart:] + } + return a } // FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points. |
