| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
+1 |
Sorry, something went wrong.
|
Would this make it into 4.0 ? |
Sorry, something went wrong.
There was a problem hiding this comment.
From JS you'll need to do if (!encoding) encoding = 'utf8';. Then from here add CHECK(args[3]->IsString()); just above this.
Sorry, something went wrong.
There was a problem hiding this comment.
At least, if args[3].IsEmpty() then .As<String>() will abort in debug mode. Need to make sure it's a string first.
Sorry, something went wrong.
|
Not sure how I feel about benchmark/fixtures/alice.html, but also don't have a better idea. Probably not for this PR, but I think a useful addition (especially now that performance will make this more usable) is the addition of a fromIndex argument. The signature may possibly be Did a quick initial review. Also want @bnoordhuis to take a look. @skomski Thanks much for the PR and for fixing my initial naive implementation. |
Sorry, something went wrong.
|
@trevnorris Buffer.indexOf already takes the argument byteOffset. It would make sense to rename the current argument byteOffset to fromIndex. |
Sorry, something went wrong.
There was a problem hiding this comment.
Can you add a static_assert(sizeof(PatternChar) == sizeof(uint16_t), "sizeof(PatternChar) == sizeof(uint16_t)") here?
Sorry, something went wrong.
Oh yup. You're right. Missed the int32_t offset = args[2]->Int32Value(); since it was moved down further. Thanks for pointing it out. As for changing fromIndex to byteOffset, do you mean just changing the name? |
Sorry, something went wrong.
There was a problem hiding this comment.
When we've confirmed what the argument type is, use args[1].As<String>(); instead. Skips some internal type checking V8 performs.
Sorry, something went wrong.
|
Always specifying an encoding like below is too much of a performance drop. +++ lib/buffer.js
@@ -399,6 +399,9 @@ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
byteOffset = -0x80000000;
byteOffset >>= 0;
+ if (encoding === undefined)
+ encoding = 'utf8';
+
if (typeof val === 'string') {
if (encoding === undefined ||
encoding === 'ucs2' ||
diff --git src/node_buffer.cc src/node_buffer.cc
index ab9d69e..2650d82 100644
--- src/node_buffer.cc
+++ src/node_buffer.cc
@@ -785,9 +785,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
ASSERT(args[1]->IsString());
ASSERT(args[2]->IsNumber());
- enum encoding enc =
- args[3].IsEmpty() ? UTF8 : ParseEncoding(args.GetIsolate(),
- args[3].As<String>(), UTF8);
+ enum encoding enc = ParseEncoding(args.GetIsolate(), args[3].As<String>(), UTF8);
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
SPREAD_ARG(args[0], ts_obj);
buffers/buffer-indexof.js search=@ iter=1: ./iojs_fastenc: 3203100 ./iojs: 2550500 ............................................................. 25.59% buffers/buffer-indexof.js search=SQ iter=1: ./iojs_fastenc: 735410 ./iojs: 698660 ............................................................... 5.26% buffers/buffer-indexof.js search=10x iter=1: ./iojs_fastenc: 2731700 ./iojs: 2237400 ........................................................... 22.10% buffers/buffer-indexof.js search=--l iter=1: ./iojs_fastenc: 162590 ./iojs: 155260 .............................................................. 4.72% buffers/buffer-indexof.js search=Alice iter=1: ./iojs_fastenc: 3695700 ./iojs: 2179300 ......................................................... 69.58% buffers/buffer-indexof.js search=Gryphon iter=1: ./iojs_fastenc: 242620 ./iojs: 245240 ......................................................... -1.07% buffers/buffer-indexof.js search=Panther iter=1: ./iojs_fastenc: 179150 ./iojs: 154900 ......................................................... 15.66% buffers/buffer-indexof.js search=Ou est ma chatte? iter=1: ./iojs_fastenc: 106870 ./iojs: 105720 ................................................ 1.08% buffers/buffer-indexof.js search=found it very iter=1: ./iojs_fastenc: 19512 ./iojs: 19658 ..................................................... -0.74% buffers/buffer-indexof.js search=among mad people iter=1: ./iojs_fastenc: 33341 ./iojs: 33526 .................................................. -0.55% buffers/buffer-indexof.js search=neighbouring pool iter=1: ./iojs_fastenc: 18422 ./iojs: 18294 .................................................. 0.70% buffers/buffer-indexof.js search=Soo--oop iter=1: ./iojs_fastenc: 14654 ./iojs: 14619 ........................................................... 0.24% buffers/buffer-indexof.js search=aaaaaaaaaaaaaaaaa iter=1: ./iojs_fastenc: 24591 ./iojs: 24638 ................................................. -0.19% buffers/buffer-indexof.js search=venture to go near the house till she had brought herself down to iter=1: ./iojs_fastenc: 79716 ./iojs: 79876 . -0.20% buffers/buffer-indexof.js search=</i> to the Caterpillar iter=1: ./iojs_fastenc: 27657 ./iojs: 28041 ........................................... -1.37% |
Sorry, something went wrong.
|
@skomski From your diff it looks like a default string is always sent. So there's no need to check args[3].IsEmpty(). Though I also have a hard time taking that at face value. The performance drop from that patch should be proportional to the number of time indexOf() is called. Which is not the case. |
Sorry, something went wrong.
There was a problem hiding this comment.
the encoding is case insensitive. look at Buffer.isEncoding() to see how we do it now to speed up the common case.
Sorry, something went wrong.
Adds the string search implementation from v8 which uses naive search if pattern length < 8 or to a specific badness then uses Boyer-Moore-Horspool Added benchmark shows the expected improvements Added option to use ucs2 encoding with Buffer::IndexOf
There was a problem hiding this comment.
Is it a concern if user does this on an odd length buffer?
Sorry, something went wrong.
|
Looks great. Amazing set of tests. If CI is happy then LGTM. |
Sorry, something went wrong.
|
Hmm.. previous test run on this failed but it's not obvious if the failure was related. Running another CI run just to make sure. If it passes, will land in master and on v4.x |
Sorry, something went wrong.
|
Some lint issues (https://ci.nodejs.org/job/node-linter/893/). I'll fix those manually when I land |
Sorry, something went wrong.
Adds the string search implementation from v8 which uses naive search if pattern length < 8 or to a specific badness then uses Boyer-Moore-Horspool Added benchmark shows the expected improvements Added option to use ucs2 encoding with Buffer::IndexOf Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> PR-URL: #2539
Adds the string search implementation from v8 which uses naive search if pattern length < 8 or to a specific badness then uses Boyer-Moore-Horspool Added benchmark shows the expected improvements Added option to use ucs2 encoding with Buffer::IndexOf Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> PR-URL: #2539
|
This change has introduced a regression on Big-Endian machines. Buffer.indexOf with a string parameter is now broken. This is blocking #3258 now and needs a fix before we can progress. Also, given that this adds a parameter to buffer.indexOf, it really ought to have been marked semver-minor. My bad as I missed that in my review. @skomski, I believe that the issue has to do with the byte ordering of the string value being passed in to Buffer.indexOf but haven't yet been able to test my theory. A bit later today I'll be able to get into the BE machine and test the theory but if you happen to get in there sooner, please let me know. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Ok thank you! I'll be able to look shortly.
|
Sorry, something went wrong.
|
@mhdawson ... Can you look at this and verify that it fixes the problem you
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Adds the string search implementation from v8
which uses naive search if pattern length < 8
or to a specific badness then uses Boyer-Moore-Horspool
Added benchmark shows the expected improvements
Added option to use ucs2 encoding with Buffer::IndexOf
Since v8 is BSD licensed it should be no problem to use the code if credited.