Skip to content

Commit 73a7298

Browse files
committed
Explain that write! is avoided for perf
1 parent c8565ca commit 73a7298

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/v0.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::convert::TryFrom;
22
use core::{char, fmt, iter, mem, str};
33

4+
// As of 2026, our custom formatting code is significantly faster than using `write!`.
45
#[allow(unused_macros)]
56
macro_rules! write {
67
($($ignored:tt)*) => {
@@ -412,6 +413,7 @@ impl Disambiguator {
412413
fn fmt_hex(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
413414
// Handle the edge case of a zero disambiguator, where the bit width is zero, but the
414415
// format is "0" (not the empty string).
416+
// This code is about 4% faster than `write!(out, "{:016x}", self.0)`.
415417
let hex_len = self.0.bit_width().div_ceil(4).max(1);
416418
let fill_len = 16 - (hex_len as usize);
417419
out.write_str(&Self::MAX_HEX_FILL[0..fill_len])?;

0 commit comments

Comments
 (0)