From cc6f7cabfdd7e48f71241ffc8e4860be6d26ba93 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 18 Jun 2024 23:14:03 -0700 Subject: helpers for those i8/u8 immediates too --- src/long_mode/display.rs | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index d6e03a9..77111b8 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -1208,24 +1208,7 @@ impl crate::long_mode::OperandVisitor for ColorizingOperandVisi fn visit_u8(&mut self, imm: u8) -> Result { self.f.span_enter(TokenType::Immediate); self.f.write_fixed_size("0x")?; - let mut buf = [MaybeUninit::::uninit(); 2]; - let mut curr = buf.len(); - let mut v = imm; - loop { - let digit = v % 16; - let c = c_to_hex(digit as u8); - curr -= 1; - buf[curr].write(c); - v = v / 16; - if v == 0 { - break; - } - } - let buf = &buf[curr..]; - let s: &str = unsafe { - core::mem::transmute::<&[MaybeUninit], &str>(buf) - }; - self.f.write_fixed_size(s)?; + self.f.write_u8(imm)?; self.f.span_end(TokenType::Immediate); Ok(()) } @@ -1237,25 +1220,7 @@ impl crate::long_mode::OperandVisitor for ColorizingOperandVisi v = -imm as u8; } self.f.write_fixed_size("0x")?; - let mut buf = [core::mem::MaybeUninit::::uninit(); 2]; - let mut curr = buf.len(); - loop { - let digit = v % 16; - let c = c_to_hex(digit as u8); - curr -= 1; - buf[curr].write(c); - v = v / 16; - if v == 0 { - break; - } - } - let buf = &buf[curr..]; - let s = unsafe { - core::mem::transmute::<&[core::mem::MaybeUninit], &str>(buf) - }; - - // not actually fixed size, but this should optimize right i hope.. - self.f.write_fixed_size(s)?; + self.f.write_u8(v)?; self.f.span_end(TokenType::Immediate); Ok(()) } -- cgit v1.1