Skip to content

Search ASCII strings from a start index without index conversion - #2362

Merged
ctate merged 1 commit into
mainfrom
ctate/search-ascii-strings-a53ab3
Oct 27, 2026
Merged

ctate merged 1 commit into
mainfrom
ctate/search-ascii-strings-a53ab3

Conversation

@ctate

@ctate ctate commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator
  • indexOf with a positive start index on an ASCII string searches bytes from that offset instead of converting between UTF-16 and byte offsets.
  • bench:runtime line-reader runs in 0.83x the time of main (186.3 -> 154.5 ms; Node 445.3 ms); the other workloads are neutral.

String.prototype.indexOf took its byte-search fast path on a proven-ASCII
receiver only when the start index was not positive. A positive start went
through the general path: ToIntegerOrInfinity, the surrogate-needle check,
and UTF-16 to byte conversions in both directions, although byte offsets
are UTF-16 indexes in an ASCII string. The fast path now covers every start
index: a positive start truncates and clamps to the length, where only the
empty needle is found, and the search runs from that byte offset.
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 26, 2026 11:23pm UTC

@ctate
ctate merged commit ad7846b into main Oct 27, 2026
123 of 128 checks passed
@ctate
ctate deleted the ctate/search-ascii-strings-a53ab3 branch October 27, 2026 00:18

This branch was successfully deployed

1 active deployment
Preview — 1245b184 Deployed Oct 26, 2026 by vercel[bot]
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.

1 participant