[PATCH] D133660: [Support] Add fast path for StringRef::find with needle of length 2.
Tatsuyuki Ishi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 18 08:37:44 PDT 2022
ishitatsuyuki updated this revision to Diff 461077.
ishitatsuyuki added a comment.
Use a simplified implementation for clarity.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133660/new/
https://reviews.llvm.org/D133660
Files:
llvm/lib/Support/StringRef.cpp
Index: llvm/lib/Support/StringRef.cpp
===================================================================
--- llvm/lib/Support/StringRef.cpp
+++ llvm/lib/Support/StringRef.cpp
@@ -148,6 +148,18 @@
const char *Stop = Start + (Size - N + 1);
+ if (N == 2) {
+ // Provide a fast path for newline finding (CRLF case) in InclusionRewriter.
+ // Not the most optimized strategy, but getting memcmp inlined should be
+ // good enough.
+ do {
+ if (std::memcmp(Start, Needle, 2) == 0)
+ return Start - Data;
+ ++Start;
+ } while (Start < Stop);
+ return npos;
+ }
+
// For short haystacks or unsupported needles fall back to the naive algorithm
if (Size < 16 || N > 255) {
do {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133660.461077.patch
Type: text/x-patch
Size: 725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220918/ad51bad9/attachment.bin>
More information about the llvm-commits
mailing list