Skip to content

Commit

Permalink
Merge pull request #915 from rintaro/lint-iswhitespace
Browse files Browse the repository at this point in the history
[Perf][WhitespaceLinter] Use hand crafted "is whitespace" function
  • Loading branch information
bnbarham authored Jan 13, 2025
2 parents 6e64b26 + 83b5f01 commit c0b518e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,16 @@ public class WhitespaceLinter {
startingAt offset: Int,
in data: [UTF8.CodeUnit]
) -> ArraySlice<UTF8.CodeUnit> {
func isWhitespace(_ char: UTF8.CodeUnit) -> Bool {
switch char {
case UInt8(ascii: " "), UInt8(ascii: "\n"), UInt8(ascii: "\t"), UInt8(ascii: "\r"), /*VT*/ 0x0B, /*FF*/ 0x0C:
return true
default:
return false
}
}
guard
let whitespaceEnd =
data[offset...].firstIndex(where: { !UnicodeScalar($0).properties.isWhitespace })
let whitespaceEnd = data[offset...].firstIndex(where: { !isWhitespace($0) })
else {
return data[offset..<data.endIndex]
}
Expand Down

0 comments on commit c0b518e

Please sign in to comment.