-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Use arrayview for bit set #4549
Use arrayview for bit set #4549
Conversation
Signed-off-by: Eric Vergnaud <[email protected]>
ignore the unrelated php failure |
4% is great for such a small and low-risk change :-) |
All (271) grammars in grammars-v4 (except three, which have the "module not found" import issue uncorrected in base class code) pass using the runtime of this PR. |
} | ||
|
||
minValue() { | ||
return Math.min.apply(null, this.values()); | ||
for (let k = 0; k < this.data.length; ++k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (count <= this.data.length) { | ||
return; | ||
} | ||
const data = new Uint32Array(count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you constructing a new array when I think Uint32Array.resize() is available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid your thinking is incorrect. You can resize an ArrayBuffer but not a TypedArray. I suspect the reason for this is that the underlying buffer is shared (a poor design decision if you ask me) so resizing a view may actually silently resize other views. Resizing the buffer would be a hack, not something I'm comfortable with
This code is definitely not correct:
You should not shift bit by index but by index mod 32. See C# code. antlr4/runtime/CSharp/src/Sharpen/BitSet.cs Line 127 in 1b3150b
|
mmm... |
antlr4/runtime/JavaScript/src/antlr4/misc/BitSet.js Lines 31 to 33 in e4a77df
Let's consider some examples. index = 0 => slot = index/32 = 0. 1<<(index%32) = 0x00000001 For index = 32, if you compute "1<<index" instead of "1<<(index%32)", the result is 0 (assuming 32-bit integer value of the shift). That's not correct. Also "index >>> 5" is computed twice in the code. |
Actually, "1<<index" is probably ok because JS has a very very weird "<<" operator unlike every programming language in existence. 1<<67 = 8 in JS. But, that is the same as 1<<(67% 32). In other words, "1<<(index % 32)" is the same as "1<<index". |
I just checked manually, it's ok. |
Fixed |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift
|
If all ok with you can you approve ? |
Implements perf improvement by using array view for bit set