From c16f318fd16c63ab8a9bf414fe2189a0399e7d8d Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 23 Mar 2021 21:21:18 -0500 Subject: [PATCH] fix: remove unnecessary allocation when loading boot rom --- src/bus.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index 290fdb4..6bfb063 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -49,12 +49,9 @@ impl Default for Bus { impl Bus { pub fn with_boot(path: &str) -> anyhow::Result { let mut file = File::open(path)?; - let mut buf = Vec::with_capacity(BOOT_ROM_SIZE); - file.read_to_end(&mut buf)?; + let mut boot_rom = [0u8; 256]; - let boot_rom: [u8; BOOT_ROM_SIZE] = buf - .try_into() - .map_err(|_| anyhow!("{} was not {} bytes in size", path, BOOT_ROM_SIZE))?; + file.read_exact(&mut boot_rom)?; Ok(Self { boot: Some(boot_rom),