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

Add Hash::from_inner and prevent double allocation in FromHex using it #40

Merged
merged 2 commits into from May 1, 2019

Conversation

Projects
None yet
3 participants
@stevenroose
Copy link
Collaborator

commented Apr 28, 2019

No description provided.

@stevenroose stevenroose requested review from apoelstra and dongcarl Apr 29, 2019

src/hex.rs Outdated
fn next_back(&mut self) -> Option<Result<u8, Error>> {
let current_len = self.sl.len();
if current_len % 2 == 1 {
Some(Err(Error::OddLengthString(self.sl.len())))

This comment has been minimized.

Copy link
@stevenroose

stevenroose May 1, 2019

Author Collaborator

Why not use current_len here?

This comment has been minimized.

Copy link
@sgeisler

sgeisler May 1, 2019

Member

I took the liberty to fix it in a separate commit, do you think I should squash it into Andrew's commit?

let current_len = self.sl.len();
if current_len % 2 == 1 {
Some(Err(Error::OddLengthString(self.sl.len())))
} else if self.sl.is_empty() {

This comment has been minimized.

Copy link
@stevenroose

stevenroose May 1, 2019

Author Collaborator

Why not use current_len here as well? I would start with if current_len == 0 { ... } else if current_len % 2 == 1 { ... } personally.

This comment has been minimized.

Copy link
@stevenroose

stevenroose May 1, 2019

Author Collaborator

But I see this is mirroring the impl of Iterator, which if fine I guess.

@stevenroose

This comment has been minimized.

Copy link
Collaborator Author

commented May 1, 2019

Can't approve my own PR. So ACK d71dd99

@stevenroose stevenroose force-pushed the stevenroose:from-hex-inner branch from d71dd99 to 3dc8dfc May 1, 2019

@sgeisler
Copy link
Member

left a comment

LGTM, please tell me if I should squash the fixup commit and reapprove.

impl<'a> DoubleEndedIterator for HexIterator<'a> {
fn next_back(&mut self) -> Option<Result<u8, Error>> {
let current_len = self.sl.len();
if current_len % 2 == 1 {

This comment has been minimized.

Copy link
@sgeisler

sgeisler May 1, 2019

Member

Imo this check shouldn't happen for every element, but I'll open a separate PR.

src/hex.rs Outdated
fn next_back(&mut self) -> Option<Result<u8, Error>> {
let current_len = self.sl.len();
if current_len % 2 == 1 {
Some(Err(Error::OddLengthString(self.sl.len())))

This comment has been minimized.

Copy link
@sgeisler

sgeisler May 1, 2019

Member

I took the liberty to fix it in a separate commit, do you think I should squash it into Andrew's commit?

@sgeisler sgeisler force-pushed the stevenroose:from-hex-inner branch from 4bbedc3 to 6b7ffd7 May 1, 2019

@apoelstra apoelstra merged commit 690c76a into rust-bitcoin:master May 1, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.