Remove some uses of foo.expect(&format!(...)) pattern

This eagerly evaluates the `format!` and produces a `String` with a heap
allocation, regardless whether `foo` is `Some`/`Ok` or `None`/`Err`. Using
`foo.unwrap_or_else(|| panic!(...))` makes it so that the error message
formatting is only evaluated if `foo` is `None`/`Err`.
This commit is contained in:
Nick Fitzgerald
2021-10-25 15:51:55 -07:00
parent 06a93d3346
commit e3a423c3e8
3 changed files with 10 additions and 8 deletions

View File

@@ -349,7 +349,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
to_bits: u8,
) -> Self::I {
let ext_mode = ExtMode::new(from_bits as u16, to_bits as u16)
.expect(&format!("invalid extension: {} -> {}", from_bits, to_bits));
.unwrap_or_else(|| panic!("invalid extension: {} -> {}", from_bits, to_bits));
if is_signed {
Inst::movsx_rm_r(ext_mode, RegMem::reg(from_reg), to_reg)
} else {