Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Two small improvements
In `librustc_apfloat/ieee.rs`, use the iterator.[r]find methods to
simplify the code. In `libserialize/json.rs`, make use of the fact
that `Vec.last` on an empty `Vec` returns `None` to simplify the
code to a single match.
  • Loading branch information
llogiq committed Aug 15, 2018
1 parent 81cfaad commit 4cae665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
18 changes: 4 additions & 14 deletions src/librustc_apfloat/ieee.rs
Expand Up @@ -2306,24 +2306,14 @@ mod sig {

/// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
pub(super) fn olsb(limbs: &[Limb]) -> usize {
for (i, &limb) in limbs.iter().enumerate() {
if limb != 0 {
return i * LIMB_BITS + limb.trailing_zeros() as usize + 1;
}
}

0
limbs.iter().enumerate().find(|(_, &limb)| limb != 0).map_or(0,
|(i, limb)| i * LIMB_BITS + limb.trailing_zeros() as usize + 1)
}

/// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
pub(super) fn omsb(limbs: &[Limb]) -> usize {
for (i, &limb) in limbs.iter().enumerate().rev() {
if limb != 0 {
return (i + 1) * LIMB_BITS - limb.leading_zeros() as usize;
}
}

0
limbs.iter().enumerate().rfind(|(_, &limb)| limb != 0).map_or(0,
|(i, limb)| (i + 1) * LIMB_BITS - limb.leading_zeros() as usize)
}

/// Comparison (unsigned) of two significands.
Expand Down
7 changes: 3 additions & 4 deletions src/libserialize/json.rs
Expand Up @@ -1387,10 +1387,9 @@ impl Stack {

// Used by Parser to test whether the top-most element is an index.
fn last_is_index(&self) -> bool {
if let Some(InternalIndex(_)) = self.stack.last() {
true
} else {
false
match self.stack.last() {
Some(InternalIndex(_)) => true,
_ => false,
}
}

Expand Down

0 comments on commit 4cae665

Please sign in to comment.