[PATCH] D133660: [Support] Add fast path for StringRef::find with needle of length 2.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 12 13:31:37 PDT 2022


efriedma added inline comments.


================
Comment at: llvm/lib/Support/StringRef.cpp:165
+      HaystackWord = HaystackWord << 16 | (uint8_t) * ++Start;
+    return NeedleWord == HaystackWord ? Start - Data - 1 : npos;
+  }
----------------
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133660/new/

https://reviews.llvm.org/D133660



More information about the llvm-commits mailing list