diff options
author | serge-sans-paille <sguelton@redhat.com> | 2020-11-26 15:22:20 +0100 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2020-12-03 20:11:11 +0100 |
commit | 9501419e879e56273f504beda3b13bf6bf82ae2b (patch) | |
tree | 2d68aadc074dd2551adfd1ea6449728c930890a4 /llvm/lib/Support/Unicode.cpp | |
parent | c288715e952fe0e179d645a76b0f518e2403a42b (diff) | |
download | llvm-9501419e879e56273f504beda3b13bf6bf82ae2b.zip llvm-9501419e879e56273f504beda3b13bf6bf82ae2b.tar.gz llvm-9501419e879e56273f504beda3b13bf6bf82ae2b.tar.bz2 |
Speedup some unicode rendering
Use a fast path for column width computation for ascii characters. Especially
relevant for llvm-objdump.
before:
% time ./bin/llvm-objdump -D -j .text /lib/libc.so.6 >/dev/null
./bin/llvm-objdump -D -j .text /lib/libc.so.6 > /dev/null 0.75s user 0.01s system 99% cpu 0.757 total
after:
% time ./bin/llvm-objdump -D -j .text /lib/libc.so.6 >/dev/null
./bin/llvm-objdump -D -j .text /lib/libc.so.6 > /dev/null 0.37s user 0.01s system 99% cpu 0.378 total
Differential Revision: https://reviews.llvm.org/D92180
Diffstat (limited to 'llvm/lib/Support/Unicode.cpp')
-rw-r--r-- | llvm/lib/Support/Unicode.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unicode.cpp b/llvm/lib/Support/Unicode.cpp index 4d19506..bb6e755 100644 --- a/llvm/lib/Support/Unicode.cpp +++ b/llvm/lib/Support/Unicode.cpp @@ -339,11 +339,22 @@ static inline int charWidth(int UCS) return 1; } +static bool isprintableascii(char c) { return c > 31 && c < 127; } + int columnWidthUTF8(StringRef Text) { unsigned ColumnWidth = 0; unsigned Length; for (size_t i = 0, e = Text.size(); i < e; i += Length) { Length = getNumBytesForUTF8(Text[i]); + + // fast path for ASCII characters + if (Length == 1) { + if (!isprintableascii(Text[i])) + return ErrorNonPrintableCharacter; + ColumnWidth += 1; + continue; + } + if (Length <= 0 || i + Length > Text.size()) return ErrorInvalidUTF8; UTF32 buf[1]; |