-
Notifications
You must be signed in to change notification settings - Fork 772
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
VM speedup by using in-place bn.js operators #98
Conversation
d1fcf0a
to
3dd278d
Compare
3dd278d
to
f367b1b
Compare
@cdetrio this could be taken into consideration when testing is working again |
This one could be merged if the tests pass. There should be a slight speed increase. |
It fails some tests, should be fixed. |
Fixed finally, should pass all tests. |
b = new BN(b) | ||
|
||
var r | ||
if (b.isZero()) { | ||
r = [0] | ||
} else { | ||
a = new BN(a) | ||
r = a.div(b).toArray('be', 32) |
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.
can do r = new BN(a).div(b).toArray('be', 32)
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.
All this was intentional to keep the change diff small and reviewable. It is going to be replaced by #159 anyway.
b = utils.fromSigned(b) | ||
|
||
var r | ||
if (b.isZero()) { | ||
r = Buffer.from([0]) | ||
} else { | ||
a = utils.fromSigned(a) | ||
r = utils.toUnsigned(a.div(b)) |
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.
can use r = utils.toUnsigned(utils.fromSigned(a).div(b))
b = new BN(b) | ||
var r | ||
if (b.isZero()) { | ||
r = [0] | ||
} else { | ||
a = new BN(a) | ||
r = a.mod(b).toArray('be', 32) |
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.
r = new BN(a).mod(b).toArray('be', 32)
b = utils.fromSigned(b) | ||
var r | ||
|
||
if (b.isZero()) { | ||
r = Buffer.from([0]) | ||
} else { | ||
a = utils.fromSigned(a) | ||
r = a.abs().mod(b.abs()) |
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.
r = utils.fromSigned(a).abs().mod(b.abs())
c = new BN(c) | ||
var r | ||
|
||
if (c.isZero()) { | ||
r = [0] | ||
} else { | ||
a = new BN(a).iadd(new BN(b)) | ||
r = a.mod(c).toArray('be', 32) |
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.
same here
c = new BN(c) | ||
var r | ||
|
||
if (c.isZero()) { | ||
r = [0] | ||
} else { | ||
a = new BN(a).imul(new BN(b)) | ||
r = a.mod(c).toArray('be', 32) |
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.
same here
* Add leveldb types * Refactor trie node * Fix lgtm warnings
Update mocha to the latest version 🚀
Replaces #37.