Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,11 @@ impl fmt::Display for Ipv6Addr {
/// Write a colon-separated part of the address
#[inline]
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
if let Some(first) = chunk.first() {
fmt::LowerHex::fmt(first, f)?;
for segment in &chunk[1..] {
if let Some((first, tail)) = chunk.split_first() {
write!(f, "{:x}", first)?;
for segment in tail {
f.write_char(':')?;
fmt::LowerHex::fmt(segment, f)?;
write!(f, "{:x}", segment)?;
Comment on lines 1616 to +1617
Copy link
Contributor

@pickfire pickfire Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                             write!(f, ":{:x}", segment)?;

Should we perhaps do this instead? I wonder if this will be optimized with reduced write calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much difference since the formatting code will call write_str on the ":" separately anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more concern about the style. However, I don't have a strong opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder if there is a performance impact. Both works for me.

}
}
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/net/ip/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ fn ipv6_addr_to_string() {

// two runs of zeros, equal length
assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string());

// don't prefix `0x` to each segment in `dbg!`.
assert_eq!("1::4:5:0:0:8", &format!("{:#?}", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8)));
}

#[test]
Expand Down