Skip to content

perf(string): bound str_region_equals scan to the compared region#302

Merged
octalide merged 1 commit into
devfrom
perf/str-region-equals-linear
Jun 23, 2026
Merged

perf(string): bound str_region_equals scan to the compared region#302
octalide merged 1 commit into
devfrom
perf/str-region-equals-linear

Conversation

@octalide

Copy link
Copy Markdown
Collaborator

Drops the whole-source str_len(s) bounds check in str_region_equals, which made the function O(file size). Since the parser calls it per keyword probe per token via at_kw, that strlen turned parsing quadratic. The loop now scans only the compared region and returns false on a NUL terminator, preserving out-of-bounds safety for valid start offsets while restoring linear-time comparison.

mach test .: 563 passed, 0 failed.

Closes #301

Drop the whole-source str_len(s) bounds check, which made the function
O(file size). The parser calls str_region_equals per keyword probe per
token via at_kw, so that strlen turned parsing quadratic. Scan only the
compared region and rely on the NUL-terminator check to preserve
out-of-bounds safety for valid start offsets, restoring linear-time
region comparison.
@octalide octalide marked this pull request as ready for review June 23, 2026 01:18
@octalide octalide merged commit 1de41fd into dev Jun 23, 2026
1 check passed
@octalide octalide deleted the perf/str-region-equals-linear branch June 23, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

str_region_equals scans the whole source, making the parser O(file²)

1 participant