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

indexOf that conforms to nodejs 10 tests #59

Merged
merged 2 commits into from Oct 4, 2018

Conversation

reconbot
Copy link
Contributor

@reconbot reconbot commented Oct 3, 2018

This is a JS implementation of indexOf for searching for BufferLists, Buffers, strings and numbers inside a BufferList. It passes the node 10 buffer indexof test suite and works on node 4+.

There are quite of a few performance improvements possible, single byte search values can use the native Buffer.indexOf command. Multibyte buffer search values could too with some extra work. I don't believe searching for another buffer list can be made much faster.

This takes largely from two places and brings them together

closes #58

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about you add a fast-path for indexOf sequences that sre 1 byte only?

LGTM on this, the optimization can come on a follow-up PR.

This is a JS implementation of indexOf for searching for BufferLists, Buffers, strings and numbers inside a BufferList. It passes the node 10 buffer indexof test suite and works on node 4+.

There are quite of a few performance improvements possible, single byte search values can use the native Buffer.indexOf command. Multibyte buffer search values could too with some extra work. I don't believe searching for another buffer list can easily be made faster.

This takes largely from two places and brings them together
- The nodejs buffer index of tests https://github.com/nodejs/node/blob/5d8373a498a50b1387464391402ef22636439303/test/parallel/test-buffer-indexof.js
- from @soldair's node-buffer-indexof https://www.npmjs.com/package/buffer-indexof
@reconbot
Copy link
Contributor Author

reconbot commented Oct 3, 2018

Removed the extra semicolons. I'll take a wack at the optimizations but I figured the test suite would help make that happen.

@reconbot
Copy link
Contributor Author

reconbot commented Oct 3, 2018

Thee 1 byte search was pretty straightforward, I'm still scratching my head at using a windowing approach for native indexOf for multibyte search. Anyway that's for another PR. if this checks out I'm done here 👍

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

indexOf()
2 participants