fix: remove unnecessary allocation when loading boot rom

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-03-23 21:21:18 -05:00
parent 48ac8317a8
commit c16f318fd1
1 changed files with 2 additions and 5 deletions

View File

@ -49,12 +49,9 @@ impl Default for Bus {
impl Bus {
pub fn with_boot(path: &str) -> anyhow::Result<Self> {
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),