From 59413d34c92cf5ce9b0e70e7105ed73a24849b3e Mon Sep 17 00:00:00 2001 From: Daniel Martí Date: Thu, 17 Aug 2017 15:51:35 +0100 Subject: all: unindent some big chunks of code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/bytes/bytes.go | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/bytes/bytes.go') 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. -- cgit v1.3