-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Removing match on constant #888
Conversation
@@ -138,7 +138,7 @@ impl Account { | |||
/// get someone who knows to call `note_code`. | |||
pub fn code(&self) -> Option<&[u8]> { | |||
match self.code_hash { | |||
Some(SHA3_EMPTY) | None if self.code_cache.is_empty() => Some(&self.code_cache), | |||
Some(c) if c == SHA3_EMPTY && self.code_cache.is_empty() => Some(&self.code_cache), | |||
Some(_) if !self.code_cache.is_empty() => Some(&self.code_cache), | |||
None => Some(&self.code_cache), |
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.
Does this actually make sense? Before this refactor we were matching None
twice:
None if self.code_cache.is_empty() => Some(&self.code_cache),
None => Some(&self.code_cache),
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.
Looks like it does not. None
matches to Some(&self.code_cache)
in all cases
@gavofyork please take a look, might be a bug in the original code.
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.
the original code (https://github.com/ethcore/parity/blob/master/ethcore/src/account.rs) was:
Some(c) if c == SHA3_EMPTY && self.code_cache.is_empty() => Some(&self.code_cache),
Some(_) if !self.code_cache.is_empty() => Some(&self.code_cache),
None => Some(&self.code_cache),
_ => None,
there are no options here which are superfluous.
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.
The code from master already contains this change (was included with #889 - otherwise there was compilation error on nightly).
This is what it looked like before:
https://github.com/ethcore/parity/blob/61420d3c9c64d87ab2c83d972c7d2d812b1d9b72/ethcore/src/account.rs#L141
The logic wasn't different, but there was superfluous | None
in first branch.
My question is rather if when this method should return None
- currently it's only the case when code_hash == SHA3_EMPTY && !code_cache.is_empty() OR code_hash != SHA3_EMPTY && code_cache.is_empty()
- this is correct?
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.
Correct (technically, the first is actually a logic error and should properly be either asserted against or an error). The second (i.e. there is definitely some non-empty code, but it isn't presently cached) properly returns None
.
@@ -138,7 +138,7 @@ impl Account { | |||
/// get someone who knows to call `note_code`. | |||
pub fn code(&self) -> Option<&[u8]> { | |||
match self.code_hash { | |||
Some(SHA3_EMPTY) | None if self.code_cache.is_empty() => Some(&self.code_cache), | |||
Some(c) if c == SHA3_EMPTY && self.code_cache.is_empty() => Some(&self.code_cache), |
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.
extra space.
needs to be resolved. |
Conflicts: ethcore/src/account.rs
Pattern matching on complex type constants without
#[derive(PartialEq)]
is being phased-out.Details:
rust-lang/rfcs#1445
We cannot derive
PartialEq
because arrays does not implement any traits.