)]}'
{
  "commit": "81ad5b02a12e08e4385d495e3b8bce1120a4519a",
  "tree": "6787fd7eea94861750ce16bd676d494661ad2a43",
  "parents": [
    "fa17ea4ba1024aaa24da88789bdbae4f54986596"
  ],
  "author": {
    "name": "Abseil Team",
    "email": "absl-team@google.com",
    "time": "Tue Nov 24 13:51:37 2026 -0800"
  },
  "committer": {
    "name": "Copybara-Service",
    "email": "copybara-worker@google.com",
    "time": "Tue Dec 01 16:50:34 2026 -0800"
  },
  "message": "Make substring search in absl worst-case linear time.\n\nabsl::StrContains(), absl::StrSplit() with a string delimiter\n(absl::ByString), absl::StrReplaceAll(), absl::StrContainsIgnoreCase() and\nabsl::Cord::Find() took O(haystack.size() * needle.size()) time in the worst\ncase. For example, searching for \"aa...ab\" in \"aaa...a\" makes\nstd::string_view::find() (memchr() for the first byte, then memcmp() for the\nwhole needle, advancing by one byte) compare almost the whole needle at every\nposition. The Boyer-Moore-Horspool searches in StrContainsIgnoreCase() and\nCord::Find() are defeated by needles like \u0027a\u0027 x k + \u0027b\u0027 + \u0027a\u0027 x k. With\ninputs of a few MB, a single call can take minutes of CPU, which is a denial\nof service risk wherever both strings come from users.\n\nThis adds strings/internal/string_search.h:\n- TwoWaySearcher\u003ckIgnoreCase\u003e: the Two-Way algorithm (Crochemore and Perrin,\n  1991) with a Horspool skip on the last byte, following glibc\u0027s\n  two_way_long_needle(). Worst-case O(n + m) time, O(1) extra memory, and\n  optionally ASCII case-insensitive.\n- NaiveSearchBudget: lets the existing fast paths do at most\n  kMaxShortNeedleSize (64) byte comparisons per haystack byte, plus an initial\n  allowance, before switching to Two-Way. Candidates are probed on their first\n  16 bytes first; candidates that fail the probe are cheap and are not\n  charged, so typical searches never switch.\n- FindLongNeedle(): the memchr() + memcmp() search under that budget, for\n  needles of more than 64 bytes. Shorter needles still use\n  std::string_view::find(), whose worst case is bounded by 64 * n.\n\nUses it in:\n- StrContains(), ByString, StrReplaceAll() and StringReplace().\n- StrReplaceAll() with several substitutions, where a long substitution can be\n  searched for again inside its previous occurrence after a shorter one is\n  applied over it: uses the needle\u0027s period from Two-Way, so the searches for\n  each substitution take linear total time. The Two-Way state is only built in\n  that case.\n- StrContainsIgnoreCase(): keeps BMH; needles of more than 64 bytes verify\n  candidates out of line under the budget and switch to case-insensitive\n  Two-Way.\n- Cord::Find(): keeps the existing chunk-wise search and BMH; needles of more\n  than 64 bytes probe candidates first and, if the budget is exhausted, copy\n  overlapping blocks of the haystack (O(needle.size() + 64 KiB) memory) and\n  search them with Two-Way.\n\nResults are unchanged. Typical inputs take the same or less time: long needles\nare up to 2x faster because the 16-byte probe is inlined, and other cases are\nwithin noise.\n\nPiperOrigin-RevId: 1029319254\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "dddb1a1bf45c8ab8126e6a428eb969783caa7bed",
      "old_mode": 33188,
      "old_path": "CMake/AbseilDll.cmake",
      "new_id": "6f7082b6917551fb9c5b78e8888cf5d570895f0a",
      "new_mode": 33188,
      "new_path": "CMake/AbseilDll.cmake"
    },
    {
      "type": "modify",
      "old_id": "f72a9fd1d96ca2565a7347da59ef96b0b03eaa6b",
      "old_mode": 33188,
      "old_path": "absl/strings/BUILD.bazel",
      "new_id": "207effc71cf882fb8e4a96825c4c2a64a57d970c",
      "new_mode": 33188,
      "new_path": "absl/strings/BUILD.bazel"
    },
    {
      "type": "modify",
      "old_id": "8ba84b5bc0a52f4e48c4728ceb4d741e7f46486f",
      "old_mode": 33188,
      "old_path": "absl/strings/CMakeLists.txt",
      "new_id": "da79b7eff5d82c6d112b7a70bf882d74d3d76996",
      "new_mode": 33188,
      "new_path": "absl/strings/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "d1271f13524db526dfa6b3abcb8d76081366407a",
      "old_mode": 33188,
      "old_path": "absl/strings/cord.cc",
      "new_id": "c0f2f4d309b35fbbef8780038b0e6d5258b604f8",
      "new_mode": 33188,
      "new_path": "absl/strings/cord.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "ee0712e5f7e3b735b743386712e90beb8fb0bf32",
      "new_mode": 33188,
      "new_path": "absl/strings/internal/string_search.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "22432fc5da3de988068b70b5df75806f19b7e01a",
      "new_mode": 33188,
      "new_path": "absl/strings/internal/string_search.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "27e7c01b0b646a773e2ac379bccb1e4f503703dc",
      "new_mode": 33188,
      "new_path": "absl/strings/internal/string_search_benchmark.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "57adf3c426d3ec3b4c675ff7e2cde5089b524e42",
      "new_mode": 33188,
      "new_path": "absl/strings/internal/string_search_test.cc"
    },
    {
      "type": "modify",
      "old_id": "ac7cf0d8249ed1eaf64f40d95fa20d00c2a696fa",
      "old_mode": 33188,
      "old_path": "absl/strings/match.cc",
      "new_id": "31d44539fda2460ad38ce7dd9eb7dd66749f3dc8",
      "new_mode": 33188,
      "new_path": "absl/strings/match.cc"
    },
    {
      "type": "modify",
      "old_id": "65bd8aa8bc22f782015a609a1bd73983e65df823",
      "old_mode": 33188,
      "old_path": "absl/strings/match.h",
      "new_id": "ce2be1031fec5af59a2a740eebf24fb9111d842e",
      "new_mode": 33188,
      "new_path": "absl/strings/match.h"
    },
    {
      "type": "modify",
      "old_id": "377e30cfd738ba407137c619346af8de4e6304ac",
      "old_mode": 33188,
      "old_path": "absl/strings/str_replace.cc",
      "new_id": "710a385efec8ac103bd99a251a9124c5f79cb5e1",
      "new_mode": 33188,
      "new_path": "absl/strings/str_replace.cc"
    },
    {
      "type": "modify",
      "old_id": "3af235793781b9512d13c1c7df6d0a099d7342d7",
      "old_mode": 33188,
      "old_path": "absl/strings/str_replace.h",
      "new_id": "fa00d82245e284e6ad1c681b6e3ef99f358484c9",
      "new_mode": 33188,
      "new_path": "absl/strings/str_replace.h"
    },
    {
      "type": "modify",
      "old_id": "abe486b915e7c0f1e6f221321f7a955de23e1416",
      "old_mode": 33188,
      "old_path": "absl/strings/str_split.cc",
      "new_id": "faf91b9ed33e2f298ea92a3d063c52bacc3272ed",
      "new_mode": 33188,
      "new_path": "absl/strings/str_split.cc"
    }
  ]
}
