Skip to content

Commit eccd157

Browse files
CrazyRokasylvestre
andauthored
perf(split): optimize FixedWidthNumber Display implementation (#10723)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
1 parent bcb890b commit eccd157

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/uu/split/src/number.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! [radix]: https://en.wikipedia.org/wiki/Radix
1616
//! [positional notation]: https://en.wikipedia.org/wiki/Positional_notation
1717
use std::error::Error;
18-
use std::fmt::{self, Display, Formatter};
18+
use std::fmt::{self, Display, Formatter, Write};
1919
use uucore::translate;
2020

2121
/// An overflow due to incrementing a number beyond its representable limit.
@@ -244,12 +244,10 @@ impl FixedWidthNumber {
244244

245245
impl Display for FixedWidthNumber {
246246
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
247-
let digits: String = self
248-
.digits
249-
.iter()
250-
.map(|d| map_digit(self.radix, *d))
251-
.collect();
252-
write!(f, "{digits}")
247+
for d in &self.digits {
248+
f.write_char(map_digit(self.radix, *d))?;
249+
}
250+
Ok(())
253251
}
254252
}
255253

0 commit comments

Comments
 (0)