[PATCH] D92180: Speedup some unicode rendering
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 26 07:21:51 PST 2020
serge-sans-paille created this revision.
serge-sans-paille added reviewers: aguinet, alexfh.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
serge-sans-paille requested review of this revision.
Use a short 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
https://reviews.llvm.org/D92180
Files:
llvm/lib/Support/Unicode.cpp
llvm/unittests/Support/UnicodeTest.cpp
Index: llvm/unittests/Support/UnicodeTest.cpp
===================================================================
--- llvm/unittests/Support/UnicodeTest.cpp
+++ llvm/unittests/Support/UnicodeTest.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Unicode.h"
+#include "llvm/Support/ConvertUTF.h"
#include "gtest/gtest.h"
namespace llvm {
@@ -23,6 +24,7 @@
EXPECT_EQ(6, columnWidthUTF8("abcdef"));
EXPECT_EQ(-1, columnWidthUTF8("\x01"));
+ EXPECT_EQ(-1, columnWidthUTF8("\t"));
EXPECT_EQ(-1, columnWidthUTF8("aaaaaaaaaa\x01"));
EXPECT_EQ(-1, columnWidthUTF8("\342\200\213")); // 200B ZERO WIDTH SPACE
@@ -84,6 +86,18 @@
EXPECT_TRUE(isPrintable(0x20000)); // CJK UNIFIED IDEOGRAPH-20000
EXPECT_FALSE(isPrintable(0x10FFFF)); // noncharacter
+
+ // test the validity of a fast path in columnWidthUTF8
+ for (unsigned char c = 0; c < 128; ++c) {
+ const UTF8 buf8[1] = {c};
+ const UTF8 *Target8 = &buf8[0];
+ UTF32 buf32[1];
+ UTF32 *Target32 = &buf32[0];
+ auto status = ConvertUTF8toUTF32(&Target8, Target8 + 1, &Target32,
+ Target32 + 1, strictConversion);
+ EXPECT_TRUE(status == conversionOK);
+ EXPECT_TRUE((bool)isprint(c) == (bool)isPrintable(buf32[0]));
+ }
}
} // namespace
Index: llvm/lib/Support/Unicode.cpp
===================================================================
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -353,6 +353,15 @@
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 (!isprint(Text[i]))
+ return ErrorNonPrintableCharacter;
+ ColumnWidth += 1;
+ continue;
+ }
+
if (Length <= 0 || i + Length > Text.size())
return ErrorInvalidUTF8;
UTF32 buf[1];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92180.307865.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201126/cb2396ca/attachment.bin>
More information about the llvm-commits
mailing list