InclusionRewriter on Windows (CRLF line endings) will exercise this in a
hot path. Calling memcmp repeatedly would be highly suboptimal for that
use case, so give it a specialized path.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
(Carried over from D133658)
A note that the N=2 search code is mostly mirrored from glibc; I believe it's short enough to not cause copyright issues but please let me know if I should be more defensive here.
llvm/lib/Support/StringRef.cpp | ||
---|---|---|
165 | How does this compare to just the following? do { if (std::memcmp(Start, Needle, 2) == 0) return Start - Data; ++Start; } while (Start < Stop); return npos; Much easier to read, and the performance is probably competitive. |
llvm/lib/Support/StringRef.cpp | ||
---|---|---|
165 | Thanks, memcmp is not as fast (always loads the Needle in the loop and loads 2 byte of Start instead of 1) but it should still provide sufficient benefit from inline expansion, so I've adopted the strategy. |
LGTM
llvm/lib/Support/StringRef.cpp | ||
---|---|---|
179 | As a future optimization, we could also look at making StringRef::count cache BadCharSkip. |
I don’t have commit rights, so can anyone commit this and https://reviews.llvm.org/D133658?
How does this compare to just the following?
Much easier to read, and the performance is probably competitive.