On this page

0189. Bound native substring search on repetitive input

Context

The endpoint skips in ADR-0062 work for normal text. With repeated bytes at both endpoints and a different byte inside the needle, each candidate can require a full-length comparison.

Decision

Supersede the long-needle search clause of ADR-0062. Keep the bounded libc path for single bytes and short needles. For long needles, keep the endpoint skips and reject mismatching short prefixes cheaply. After a fixed number of unsuccessful full comparisons, use Two-Way matching for the remaining candidates. Search work is linear in the combined input lengths and uses constant extra storage. The algorithm is described in the Crochemore and Perrin paper.

Alternatives considered

Consequences

Bytewise first-match offsets and empty-needle behavior stay fixed. The native reference test and the search benchmark exercise the fallback, including the repetitive case. The interpreter keeps the same bytewise semantics.