-
Notifications
You must be signed in to change notification settings - Fork 52
Add Hash::from_inner and prevent double allocation in FromHex using it #40
Conversation
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()))) |
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 not use current_len
here?
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 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() { |
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 not use current_len
here as well? I would start with if current_len == 0 { ... } else if current_len % 2 == 1 { ... }
personally.
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.
But I see this is mirroring the impl of Iterator
, which if fine I guess.
Can't approve my own PR. So ACK d71dd99 |
d71dd99
to
3dc8dfc
Compare
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.
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 { |
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.
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()))) |
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 took the liberty to fix it in a separate commit, do you think I should squash it into Andrew's commit?
No description provided.