From 6631bc777affdbb371b64495c4aeb34b031cf7a1 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Sun, 17 Aug 2025 07:42:20 +0200 Subject: Use a buffered reader for incbin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iterating via `bytes()` on a file is inefficient as the default implementation calls `read` on each byte, which can be costly on bytes which are not in memory like files. This is extra important for statements like `incbin` as included files can be rather big. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 5b01db8..6fc0cc1 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -8,7 +8,7 @@ use crate::SourceInfo; use std::cmp::Ordering; use std::collections::HashMap; use std::fs::File; -use std::io::Read; +use std::io::{BufReader, Read}; use std::ops::Neg; /// The mode in which a literal is expressed. @@ -1497,7 +1497,8 @@ impl<'a> Assembler<'a> { } // And finally just push each byte from the given file as a fill bundle. - for byte in file.bytes() { + let reader = BufReader::new(file); + for byte in reader.bytes() { match byte { Ok(b) => self.push_bundle(Bundle::fill(b), node)?, Err(_) => break, -- cgit v1.2.3