[PATCH] D97320: Use a fast path when initializing LineOffsetMapping
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 1 01:23:59 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80e8efd563fd: Use a fast path when initializing LineOffsetMapping (authored by serge-sans-paille).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97320/new/
https://reviews.llvm.org/D97320
Files:
clang/lib/Basic/SourceManager.cpp
Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1270,13 +1270,16 @@
const std::size_t BufLen = End - Buf;
unsigned I = 0;
while (I < BufLen) {
- if (Buf[I] == '\n') {
- LineOffsets.push_back(I + 1);
- } else if (Buf[I] == '\r') {
- // If this is \r\n, skip both characters.
- if (I + 1 < BufLen && Buf[I + 1] == '\n')
- ++I;
- LineOffsets.push_back(I + 1);
+ // Use a fast check to catch both newlines
+ if (LLVM_UNLIKELY(Buf[I] <= std::max('\n', '\r'))) {
+ if (Buf[I] == '\n') {
+ LineOffsets.push_back(I + 1);
+ } else if (Buf[I] == '\r') {
+ // If this is \r\n, skip both characters.
+ if (I + 1 < BufLen && Buf[I + 1] == '\n')
+ ++I;
+ LineOffsets.push_back(I + 1);
+ }
}
++I;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97320.327049.patch
Type: text/x-patch
Size: 938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210301/92b9f19e/attachment.bin>
More information about the cfe-commits
mailing list