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

all: unify big.Int zero checks, use common/math in more places #3716

Merged
merged 3 commits into from
Feb 28, 2017

Conversation

fjl
Copy link
Contributor

@fjl fjl commented Feb 27, 2017

No description provided.

fjl added 3 commits February 27, 2017 00:32
name              old time/op    new time/op    delta
PaddedBigBytes-8    71.1ns ± 5%    46.1ns ± 1%  -35.15%  (p=0.000 n=20+19)

name              old alloc/op   new alloc/op   delta
PaddedBigBytes-8     48.0B ± 0%     32.0B ± 0%  -33.33%  (p=0.000 n=20+20)
Various checks were in use. This commit replaces them all with Int.Sign,
which is cheaper and less code.

eg templates:

    func before(x *big.Int) bool { return x.BitLen() == 0 }
    func after(x *big.Int) bool  { return x.Sign() == 0 }

    func before(x *big.Int) bool { return x.BitLen() > 0 }
    func after(x *big.Int) bool  { return x.Sign() != 0 }

    func before(x *big.Int) int { return x.Cmp(common.Big0) }
    func after(x *big.Int) int  { return x.Sign() }
@mention-bot
Copy link

@fjl, thanks for your PR! By analyzing the history of the files in this pull request, we identified @obscuren, @zsfelfoldi and @karalabe to be potential reviewers.

privkey = make([]byte, 32)
readBits(privkey, key.D)
return pubkey, privkey
return pubkey, math.PaddedBigBytes(key.D, 32)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the original code to right padding and this one left padding?

Copy link
Member

Choose a reason for hiding this comment

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

Ah no, I see readBits is filling from the back to the front.

@karalabe karalabe added this to the 1.6.0 milestone Feb 27, 2017
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

@fjl fjl requested review from obscuren and holiman February 28, 2017 10:39
@obscuren obscuren merged commit 5f78262 into ethereum:master Feb 28, 2017
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.

4 participants