Hi internals,

I'd like to open discussion on this RFC:
https://wiki.php.net/rfc/prepared_literal_string_matching

It proposes Str\Matcher and Str\Replacer for prepared literal substring
search and replacement. Matcher provides presence checks, unique matched
keywords, occurrence counts, and enumeration of all overlapping matches
with byte offsets, using Str\MatchResult objects. Replacer performs
non-overlapping replacements, choosing the earliest start and then the
longest key, without rescanning inserted text.

Both classes prepare an immutable dictionary during construction.
Matching is byte-oriented, binary-safe, and case-sensitive. Objects can be
reused within a request or in long-running applications.

I've implemented the API and published reproducible benchmarks covering
both prepared calls and one-shot use, including construction and
destruction.
Preparation can pay off even for a single call on some inputs. On others,
existing PHP functions or PCRE remain faster, even than a prepared object.

I propose including these classes in ext/standard in the Str namespace.
The current implementation is in ext/strmatch. I'd welcome feedback on
the API, integration, error types, and whether Matcher and Replacer
should be considered together or separately.

Implementation:
https://github.com/php/php-src/pull/25122

Benchmarks, methodology and raw data:
https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/multi-pattern-search
-- 
Best regards,
Artem Ukrainskiy

Reply via email to