diff options
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | llvm/lib/Support/StringRef.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index 096b2d2..7e19a79 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -148,6 +148,18 @@ size_t StringRef::find(StringRef Str, size_t From) const { 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 { |