Always inline the contains function

This function is commonly called in a loop (or iterator). Inlining it
makes it run faster, which is beneficial in this case.
This commit is contained in:
Abhishek Chanda
2021-04-04 23:05:57 -05:00
parent 14108098d6
commit 9921661ebe
4 changed files with 4 additions and 1 deletions

View File

@ -163,6 +163,7 @@ impl Ipv4Network {
/// assert!(net.contains(Ipv4Addr::new(127, 0, 0, 70)));
/// assert!(!net.contains(Ipv4Addr::new(127, 0, 1, 70)));
/// ```
#[inline]
pub fn contains(self, ip: Ipv4Addr) -> bool {
let mask = !(0xffff_ffff as u64 >> self.prefix) as u32;
let net = u32::from(self.addr) & mask;