Clean up iterator chains

These were flagged by `cargo clippy`:

    warning: called `is_some()` after searching an `Iterator` with find.
             This is more succinctly expressed by calling `any()`.
    warning: this `.into_iter()` call is equivalent to `.iter_mut()` and
             will not consume the `BTreeMap`
    warning: called `skip_while(p).next()` on an `Iterator`

The skip_while conversion is a little tricky. Clippy notes that:

    warning: called `skip_while(p).next()` on an `Iterator`
    help: this is more succinctly expressed by calling `.find(!p)` instead

So the condition of the skip_while is inverted and then simplified using
De Morgan's laws.
This commit is contained in:
Alex Crawford 2020-12-25 23:24:32 -08:00
parent 81ddfe734f
commit e78c9576b2
3 changed files with 5 additions and 7 deletions

View File

@ -721,7 +721,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
/// [RFC 4291 § 2.7.1]: https://tools.ietf.org/html/rfc4291#section-2.7.1
#[cfg(feature = "proto-ipv6")]
pub fn has_solicited_node(&self, addr: Ipv6Address) -> bool {
self.ip_addrs.iter().find(|cidr| {
self.ip_addrs.iter().any(|cidr| {
match *cidr {
IpCidr::Ipv6(cidr) if cidr.address() != Ipv6Address::LOOPBACK=> {
// Take the lower order 24 bits of the IPv6 address and
@ -730,7 +730,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
}
_ => false,
}
}).is_some()
})
}
/// Check whether the interface has the given IP address assigned.
@ -1522,8 +1522,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
fn in_same_network(&self, addr: &IpAddress) -> bool {
self.ip_addrs
.iter()
.find(|cidr| cidr.contains_addr(addr))
.is_some()
.any(|cidr| cidr.contains_addr(addr))
}
fn route(&self, addr: &IpAddress, timestamp: Instant) -> Result<IpAddress> {

View File

@ -106,7 +106,7 @@ impl<'a> Cache<'a> {
#[cfg(any(feature = "std", feature = "alloc"))]
ManagedMap::Owned(ref mut map) => {
if current_storage_size >= self.gc_threshold {
let new_btree_map = map.into_iter()
let new_btree_map = map.iter_mut()
.map(|(key, value)| (*key, *value))
.filter(|(_, v)| timestamp < v.expires_at)
.collect();

View File

@ -961,8 +961,7 @@ impl<'a> TcpSocket<'a> {
reply_repr.sack_ranges[0] = self.assembler.iter_data(
reply_repr.ack_number.map(|s| s.0 as usize).unwrap_or(0))
.map(|(left, right)| (left as u32, right as u32))
.skip_while(|(left, right)| *left > last_seg_seq || *right < last_seg_seq)
.next();
.find(|(left, right)| *left <= last_seg_seq && *right >= last_seg_seq);
}
if reply_repr.sack_ranges[0].is_none() {