Skip to content

Commit f70d457

Browse files
committed
strings: unindent Fields
CL 56470 unindented bytes.Fields, but not strings.Fields. Do so now to make it easier to diff the two functions for potential differences. Change-Id: Ifef81f50cee64e8277e91efa5ec5521d8d21d3bd Reviewed-on: https://go-review.googlesource.com/c/go/+/170951 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent 20995f6 commit f70d457

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/strings/strings.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -341,38 +341,38 @@ func Fields(s string) []string {
341341
wasSpace = isSpace
342342
}
343343

344-
if setBits < utf8.RuneSelf { // ASCII fast path
345-
a := make([]string, n)
346-
na := 0
347-
fieldStart := 0
348-
i := 0
349-
// Skip spaces in the front of the input.
350-
for i < len(s) && asciiSpace[s[i]] != 0 {
344+
if setBits >= utf8.RuneSelf {
345+
// Some runes in the input string are not ASCII.
346+
return FieldsFunc(s, unicode.IsSpace)
347+
}
348+
// ASCII fast path
349+
a := make([]string, n)
350+
na := 0
351+
fieldStart := 0
352+
i := 0
353+
// Skip spaces in the front of the input.
354+
for i < len(s) && asciiSpace[s[i]] != 0 {
355+
i++
356+
}
357+
fieldStart = i
358+
for i < len(s) {
359+
if asciiSpace[s[i]] == 0 {
351360
i++
361+
continue
352362
}
353-
fieldStart = i
354-
for i < len(s) {
355-
if asciiSpace[s[i]] == 0 {
356-
i++
357-
continue
358-
}
359-
a[na] = s[fieldStart:i]
360-
na++
363+
a[na] = s[fieldStart:i]
364+
na++
365+
i++
366+
// Skip spaces in between fields.
367+
for i < len(s) && asciiSpace[s[i]] != 0 {
361368
i++
362-
// Skip spaces in between fields.
363-
for i < len(s) && asciiSpace[s[i]] != 0 {
364-
i++
365-
}
366-
fieldStart = i
367-
}
368-
if fieldStart < len(s) { // Last field might end at EOF.
369-
a[na] = s[fieldStart:]
370369
}
371-
return a
370+
fieldStart = i
372371
}
373-
374-
// Some runes in the input string are not ASCII.
375-
return FieldsFunc(s, unicode.IsSpace)
372+
if fieldStart < len(s) { // Last field might end at EOF.
373+
a[na] = s[fieldStart:]
374+
}
375+
return a
376376
}
377377

378378
// FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c)

0 commit comments

Comments
 (0)