Skip to content

Commit 8073ddc

Browse files
committed
Revert "PrettyPrinterPerformance Optimized the PrettyPrinter for #894"
1 parent f334bb3 commit 8073ddc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Sources/SwiftFormat/PrettyPrint/PrettyPrintBuffer.swift

+9-10
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,16 @@ struct PrettyPrintBuffer {
122122
// In case of comments, we may get a multi-line string.
123123
// To account for that case, we need to correct the lineNumber count.
124124
// The new column is only the position within the last line.
125-
var lastLength = 0
126-
// We are only interested in "\n" we can use the UTF8 view and skip the grapheme clustering.
127-
for element in text.utf8 {
128-
if element == UInt8(ascii: "\n") {
129-
lineNumber += 1
130-
lastLength = 0
131-
} else {
132-
lastLength += 1
133-
}
125+
let lines = text.split(separator: "\n")
126+
lineNumber += lines.count - 1
127+
if lines.count > 1 {
128+
// in case we have inserted new lines, we need to reset the column
129+
column = lines.last?.count ?? 0
130+
} else {
131+
// in case it is an end of line comment or a single line comment,
132+
// we just add to the current column
133+
column += lines.last?.count ?? 0
134134
}
135-
column += lastLength
136135
}
137136

138137
/// Request that the given number of spaces be printed out before the next text token.

0 commit comments

Comments
 (0)