mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +00:00
Get rid of the use of str.repeat()
This allocates a string. Instead we can (ab)use format specifiers to do the repetitions for us.
This commit is contained in:
1 parent
2e403a2d11
commit
7b7a0ff32d
1 file changed
+15
-25
+15
-25
@@ -92,25 +92,19 @@ impl<'a> Printer<'a> {
|
|||||||
fn header(&mut self) {
|
fn header(&mut self) {
|
||||||
writeln!(
|
writeln!(
|
||||||
self.stdout,
|
self.stdout,
|
||||||
"┌{}┬{}┬{}┬{}┬{}┐",
|
"┌{0:─<8}┬{0:─<25}┬{0:─<25}┬{0:─<8}┬{0:─<8}┐",
|
||||||
"─".repeat(8),
|
""
|
||||||
"─".repeat(3 * 8 + 1),
|
)
|
||||||
"─".repeat(3 * 8 + 1),
|
.ok();
|
||||||
"─".repeat(8),
|
|
||||||
"─".repeat(8)
|
|
||||||
).ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer(&mut self) {
|
fn footer(&mut self) {
|
||||||
writeln!(
|
writeln!(
|
||||||
self.stdout,
|
self.stdout,
|
||||||
"└{}┴{}┴{}┴{}┴{}┘",
|
"└{0:─<8}┴{0:─<25}┴{0:─<25}┴{0:─<8}┴{0:─<8}┘",
|
||||||
"─".repeat(8),
|
""
|
||||||
"─".repeat(3 * 8 + 1),
|
)
|
||||||
"─".repeat(3 * 8 + 1),
|
.ok();
|
||||||
"─".repeat(8),
|
|
||||||
"─".repeat(8)
|
|
||||||
).ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_byte(&mut self, b: u8) -> io::Result<()> {
|
fn print_byte(&mut self, b: u8) -> io::Result<()> {
|
||||||
@@ -146,12 +140,13 @@ impl<'a> Printer<'a> {
|
|||||||
if len < 8 {
|
if len < 8 {
|
||||||
write!(
|
write!(
|
||||||
self.stdout,
|
self.stdout,
|
||||||
"{}┊{}│",
|
"{0:1$}┊{0:2$}│",
|
||||||
" ".repeat(3 * (8 - len)),
|
"",
|
||||||
" ".repeat(1 + 3 * 8)
|
3 * (8 - len),
|
||||||
|
1 + 3 * 8
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
write!(self.stdout, "{}│", " ".repeat(3 * (16 - len)))?;
|
write!(self.stdout, "{0:1$}│", "", 3 * (16 - len))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut idx = 1;
|
let mut idx = 1;
|
||||||
@@ -167,14 +162,9 @@ impl<'a> Printer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len < 8 {
|
if len < 8 {
|
||||||
writeln!(
|
writeln!(self.stdout, "{0:1$}┊{0:2$}│ ", "", 8 - len, 8)?;
|
||||||
self.stdout,
|
|
||||||
"{}┊{}│ ",
|
|
||||||
" ".repeat(8 - len),
|
|
||||||
" ".repeat(8)
|
|
||||||
)?;
|
|
||||||
} else {
|
} else {
|
||||||
writeln!(self.stdout, "{}│", " ".repeat(16 - len))?;
|
writeln!(self.stdout, "{0:1$}│", "", 16 - len)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.line.clear();
|
self.line.clear();
|
||||||
|
|||||||
Reference in new issue
Block a user