Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: add indexOf/lastIndexOf method #161

Closed
wants to merge 2 commits into from
Closed

buffer: add indexOf/lastIndexOf method #161

wants to merge 2 commits into from

Conversation

algesten
Copy link

Expanded on @srijs code to add a Buffer.prototype.lastIndexOf. I used a strategy of divide/conquer, but since I'm a total c++ idiot, I have no idea whether there is a better way (some reverse memcmp variant?). Also I rebased both srijs and these commits against v0.12 hoping it would make it out sooner :)

Adds a `.indexOf` method to `Buffer`, which borrows semantics from
both `Array.prototype.indexOf` and `String.prototype.indexOf`.

`Buffer.prototype.indexOf` can be invoked with a Buffer, a string
or a number as the needle.  If the needle a Buffer or string, it will
find the first occurrence of this sequence of bytes.  If the needle is
a number, it will find the first occurrence of this byte.

Reviewed-by: Sam Rijs <srijs@airpost.net>
Fixes: #95
PR-URL: #160
Expanding and reusing code by Sam Rijs in commit 4dedc09 to also add a
`.lastIndexOf` method to `Buffer`.

`Buffer.prototype.lastIndexOf` takes the same arguments as its
predecessor and uses a divide-and-conquer method to find the last
occurrence of the sequence of byte.

Reviewed-by: Martin Algesten <martin@algesten.se>
Related-To: #95
Original PR-URL: #160
PR-URL: #161
@piscisaureus piscisaureus reopened this Dec 30, 2014
@rvagg rvagg added the semver-minor PRs that contain new features and should be released in the next minor version. label Jan 23, 2015
@brendanashworth
Copy link
Contributor

I have no opinion on the subject but from what I'm seeing is that #561 will supersede this PR. However, it has been indicated that there will be no .lastIndexOf() method added in that PR, so I think that is still up for grabs.

I'm unsure with how to proceed with this specific PR, as only one commit seems to be prevalent now. @algesten?

@trevnorris
Copy link
Contributor

I'm really sorry. Been tied up with work, which is why I haven't finished my lastIndexOf() PR. I'll finish that this weekend and get it merged in. @algesten if you then want to replicate the same structure for lastIndexOf() and submit another PR that would be great. :)

@chrisdickinson
Copy link
Contributor

Closing this in favor of #561. @algesten, if you're interested in adding lastIndexOf based on @trevnorris' code, please open another PR. Thanks!

@algesten
Copy link
Author

Thanks @chrisdickinson I'll try to make some time to look into it.

boingoing pushed a commit to boingoing/node that referenced this pull request Apr 6, 2017
eti-p-doray pushed a commit to eti-p-doray/node that referenced this pull request Dec 5, 2023
V8 will increase the maximum TypedArray size in
https://crrev.com/c/4872536; this CL adapts the tests to allow for that.

Tests that hard-code smaller sizes or are already tested in V8 are
removed; one test is adapted to not rely on a specific limit.
# Conflicts:
#	test/parallel/test-buffer-alloc.js
#	test/parallel/test-buffer-tostring-rangeerror.js
eti-p-doray pushed a commit to eti-p-doray/node that referenced this pull request May 28, 2024
V8 will increase the maximum TypedArray size in
https://crrev.com/c/4872536; this CL adapts the tests to allow for that.

Tests that hard-code smaller sizes or are already tested in V8 are
removed; one test is adapted to not rely on a specific limit.
# Conflicts:
#	test/parallel/test-buffer-alloc.js
#	test/parallel/test-buffer-tostring-rangeerror.js
syg pushed a commit to syg/node that referenced this pull request Jun 20, 2024
V8 will increase the maximum TypedArray size in
https://crrev.com/c/4872536; this CL adapts the tests to allow for that.

Tests that hard-code smaller sizes or are already tested in V8 are
removed; one test is adapted to not rely on a specific limit.
# Conflicts:
#	test/parallel/test-buffer-alloc.js
#	test/parallel/test-buffer-tostring-rangeerror.js
eti-p-doray pushed a commit to eti-p-doray/node that referenced this pull request Aug 28, 2024
V8 will increase the maximum TypedArray size in
https://crrev.com/c/4872536; this CL adapts the tests to allow for that.

Tests that hard-code smaller sizes or are already tested in V8 are
removed; one test is adapted to not rely on a specific limit.
# Conflicts:
#	test/parallel/test-buffer-alloc.js
#	test/parallel/test-buffer-tostring-rangeerror.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants