2
Github Add `#[inline]` to IpAddr methods by AngelicosPhosphoros · Pull Request #...
source link: https://github.com/rust-lang/rust/pull/83831
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Code from issue:
use std::net::{Ipv4Addr, Ipv6Addr}; pub fn ipv4_bitand_mask(ipv4: Ipv4Addr, mask: u32) -> Ipv4Addr { let ipv4_u32 = u32::from_ne_bytes(ipv4.octets()); Ipv4Addr::from((ipv4_u32 & mask).to_ne_bytes()) } pub fn ipv6_bitand_mask(ipv6: Ipv6Addr, mask: u128) -> Ipv6Addr { let ipv6_u128 = u128::from_ne_bytes(ipv6.octets()); Ipv6Addr::from((ipv6_u128 & mask).to_ne_bytes()) }
Generated asm:
_ZN9inline_ip16ipv4_bitand_mask17h21a1d58399eeef05E: movl %ecx, %eax andl %edx, %eax retq _ZN9inline_ip16ipv6_bitand_mask17h84a3a89719ccdfc1E: movq %rcx, %rax andq %r8, %rax andq %r9, %rdx retq
I think, this change is very trivial.
cc @LeSeulArtichaut @mati865
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK