Skip to content

Commit c0b518e

Browse files
authored
Merge pull request #915 from rintaro/lint-iswhitespace
[Perf][WhitespaceLinter] Use hand crafted "is whitespace" function
2 parents 6e64b26 + 83b5f01 commit c0b518e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,16 @@ public class WhitespaceLinter {
339339
startingAt offset: Int,
340340
in data: [UTF8.CodeUnit]
341341
) -> ArraySlice<UTF8.CodeUnit> {
342+
func isWhitespace(_ char: UTF8.CodeUnit) -> Bool {
343+
switch char {
344+
case UInt8(ascii: " "), UInt8(ascii: "\n"), UInt8(ascii: "\t"), UInt8(ascii: "\r"), /*VT*/ 0x0B, /*FF*/ 0x0C:
345+
return true
346+
default:
347+
return false
348+
}
349+
}
342350
guard
343-
let whitespaceEnd =
344-
data[offset...].firstIndex(where: { !UnicodeScalar($0).properties.isWhitespace })
351+
let whitespaceEnd = data[offset...].firstIndex(where: { !isWhitespace($0) })
345352
else {
346353
return data[offset..<data.endIndex]
347354
}

0 commit comments

Comments
 (0)