From 36b50b8c55e47337029134480e833581b9442b82 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Tue, 18 Jul 2023 09:23:12 +1000 Subject: [PATCH] use arrays for buffers --- lib/src/processor/memory/mmio/gpu.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index ed4ec9d..30619c4 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -28,19 +28,19 @@ where ColourFormat: From + Copy, R: Renderer, { - pub buffer: Vec, + pub buffer: [ColourFormat; WIDTH * HEIGHT], pub vram: Vram, pub oam: Oam, pub window: R, - is_bg_zero: Vec, - is_bg_priority: Vec, + is_bg_zero: [bool; WIDTH], + is_bg_priority: [bool; WIDTH], lcdc: Lcdc, stat: Stat, mode_clock: usize, scanline: u8, lyc: u8, tile_window: Option>, - layer_window: Option<(R, Vec)>, + layer_window: Option<(R, [ColourFormat; WIDTH * HEIGHT * 3])>, window_lc: u8, has_window_been_enabled: bool, bg_palette: Palette, @@ -74,14 +74,11 @@ where ColourInner::Error.rgb_bytes(None).into() }; - let buffer = vec![blank_colour.clone(); WIDTH * HEIGHT]; + let buffer = [blank_colour; WIDTH * HEIGHT]; let layer_window = layer_window_renderer.map(|mut layer_window_renderer| { layer_window_renderer.prepare(WIDTH, HEIGHT * 3); - ( - layer_window_renderer, - vec![blank_colour; WIDTH * HEIGHT * 3], - ) + (layer_window_renderer, [blank_colour; WIDTH * HEIGHT * 3]) }); Self { @@ -89,8 +86,8 @@ where vram: Vram::new(cgb), oam: Oam::default(), window, - is_bg_zero: vec![true; WIDTH], - is_bg_priority: vec![false; WIDTH], + is_bg_zero: [true; WIDTH], + is_bg_priority: [false; WIDTH], lcdc: Lcdc::default(), stat: Stat::default(), mode_clock: 0, @@ -495,7 +492,7 @@ where ColourInner::Error.rgb_bytes(None).into() }; for val in buffer { - *val = blank_colour.clone(); + *val = blank_colour; } } }