-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
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
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 I'm unsure with how to proceed with this specific PR, as only one commit seems to be prevalent now. @algesten? |
I'm really sorry. Been tied up with work, which is why I haven't finished my |
Closing this in favor of #561. @algesten, if you're interested in adding |
Thanks @chrisdickinson I'll try to make some time to look into it. |
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
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
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
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
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 :)