From 7ab69f66b983eba11e9864234585265f334caac0 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 16 Jun 2024 13:03:28 -0700 Subject: use less of core::fmt, write by hand `name()` returning a `[u8; 2]` is nice when there is a specializing and unrolling write implementation, whereas `&str` might not consistently unroll into a simple 2-byte copy (rather than loop). it'll look a little more reasonable soon, hopefully.. --- src/long_mode/display.rs | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/long_mode') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index 4725154..3ccbb0f 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -446,7 +446,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{}]", self.colors.address(u32_hex(imm))) } @@ -454,7 +457,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{}]", self.colors.address(u64_hex(imm))) } @@ -462,8 +468,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}", prefix)?; - self.f.write_str(":")?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } self.f.write_str("[")?; self.f.write_str(regspec_label(®))?; @@ -475,7 +483,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } self.f.write_str("[")?; self.f.write_str(regspec_label(®))?; @@ -485,7 +496,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{} * {}]", regspec_label(®), @@ -496,7 +510,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{} * {} ", regspec_label(®), @@ -509,7 +526,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{} + {} * {}]", regspec_label(&base), @@ -521,7 +541,10 @@ impl crate::long_mode::OperandVisitor for Colorizi self.f.write_str(MEM_SIZE_STRINGS[self.instr.mem_size as usize])?; self.f.write_str(" ")?; if let Some(prefix) = self.instr.segment_override_for_op(self.op_nr) { - write!(self.f, "{}:", prefix)?; + let name = prefix.name(); + self.f.write_char(name[0] as char)?; + self.f.write_char(name[1] as char)?; + self.f.write_char(':')?; } write!(self.f, "[{} + {} * {} ", regspec_label(&base), -- cgit v1.1