Skip to content

Restructure needle handling and expand search algorithm#9

Open
jasnell wants to merge 5 commits intomainfrom
fixups
Open

Restructure needle handling and expand search algorithm#9
jasnell wants to merge 5 commits intomainfrom
fixups

Conversation

@jasnell
Copy link
Collaborator

@jasnell jasnell commented Mar 7, 2026

  • Replace the declarative search (SequenceSameValueZeroEqual) with an explicit naive linear search algorithm in TypedArraySearchSubsequence, with an editor note that implementations may use any equivalent algorithm (Boyer-Moore, two-way, etc.). Early break on inner loop mismatch.

  • Remove the Needle-as-Iterable following committee discussion

  • Rename to indexOfSequence / lastIndexOfSequence

  • Remove contains

  • TypedArraySubsequenceFromTypedArray: reads needle elements directly from the underlying buffer via GetValueFromBuffer. No user code is invoked; @@iterator is not called. Checks [[ContentType]] compatibility.

  • Methods dispatch based on [[TypedArrayName]] internal slot presence.

Update README and TEST_CASES.md to reflect the two-path design.

Replace the declarative search (SequenceSameValueZeroEqual) with an
explicit naive linear search algorithm in TypedArraySearchSubsequence,
with an editor note that implementations may use any equivalent
algorithm (Boyer-Moore, two-way, etc.). Early break on inner loop
mismatch.

Split ToCompatibleTypedArrayElementList into two paths following the
%TypedArray%.prototype.set precedent (SetTypedArrayFromTypedArray vs
SetTypedArrayFromArrayLike):

- TypedArraySubsequenceFromTypedArray: reads needle elements directly
  from the underlying buffer via GetValueFromBuffer. No user code is
  invoked; @@iterator is not called. Checks [[ContentType]] compatibility.
- TypedArraySubsequenceFromIterable: the existing @@iterator path for
  non-TypedArray iterables (Arrays, generators, Sets, etc.).

Methods dispatch based on [[TypedArrayName]] internal slot presence.

Additional spec fixes from review:

- ValidateIntegralNumber: use "integral Number" term instead of manual
  NaN + truncate checks (fixes ±Infinity gap, matches concat proposal)
- Add "not generic" boilerplate to all three methods
- Add early return when haystackLength is 0
- Fix searchLast degenerate clamping range [0, -1] for empty arrays
- Add notes for empty-needle semantics and evaluation order

Update README and TEST_CASES.md to reflect the two-path design.
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

The rendered spec for this PR is available at https://tc39.es/proposal-typedarray-findwithin/pr/9.

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