Skip to content

Commit da23a83

Browse files
authored
[FormattedStream] Add ASCII fast path (#117892)
Printing IR spends a large amount of time updating the column count via generic UTF-8 APIs. Speed it up by adding a fast path for the common printable ASCII case. This makes `-print-on-crash -print-module-scope` about two times faster.
1 parent ccc471f commit da23a83

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/lib/Support/FormattedStream.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ void formatted_raw_ostream::UpdatePosition(const char *Ptr, size_t Size) {
7575
// Now scan the rest of the buffer.
7676
unsigned NumBytes;
7777
for (const char *End = Ptr + Size; Ptr < End; Ptr += NumBytes) {
78+
// Fast path for printable ASCII characters without special handling.
79+
if (*Ptr >= 0x20 && *Ptr <= 0x7e) {
80+
NumBytes = 1;
81+
++Column;
82+
continue;
83+
}
84+
7885
NumBytes = getNumBytesForUTF8(*Ptr);
7986

8087
// The buffer might end part way through a UTF-8 code unit sequence for a

0 commit comments

Comments
 (0)