From 7b43debd3e20aba14a8af3f2cd0a08248e2adc55 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 20:13:03 +0000 Subject: [PATCH] WIP: Try removing the hashmap --- agb/Cargo.lock | 40 ------------------- agb/Cargo.toml | 2 - agb/src/display/tiled/vram_manager.rs | 20 +++++----- .../the-hat-chooses-the-wizard/Cargo.lock | 40 ------------------- examples/the-purple-night/Cargo.lock | 40 ------------------- 5 files changed, 11 insertions(+), 131 deletions(-) diff --git a/agb/Cargo.lock b/agb/Cargo.lock index 3ea5f3c7..472cef4a 100644 --- a/agb/Cargo.lock +++ b/agb/Cargo.lock @@ -24,8 +24,6 @@ dependencies = [ "agb_sound_converter", "bare-metal", "bitflags", - "hashbrown", - "rustc-hash", ] [[package]] @@ -67,17 +65,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -149,15 +136,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" -dependencies = [ - "ahash", -] - [[package]] name = "hound" version = "3.4.0" @@ -235,12 +213,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" - [[package]] name = "png" version = "0.17.5" @@ -307,12 +279,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "serde" version = "1.0.136" @@ -359,12 +325,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/agb/Cargo.toml b/agb/Cargo.toml index 55af71f6..dbd7d298 100644 --- a/agb/Cargo.toml +++ b/agb/Cargo.toml @@ -21,13 +21,11 @@ freq18157 = ["agb_sound_converter/freq18157"] [dependencies] bitflags = "1.3" -hashbrown = "0.12.0" agb_image_converter = { version = "0.6.0", path = "../agb-image-converter" } agb_sound_converter = { version = "0.1.0", path = "../agb-sound-converter" } agb_macros = { version = "0.1.0", path = "../agb-macros" } agb_fixnum = { version = "0.1.0", path = "../agb-fixnum" } bare-metal = "1.0" -rustc-hash = { version = "1.0", default-features = false } [package.metadata.docs.rs] default-target = "thumbv6m-none-eabi" diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index 249023ba..1da86d9f 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -10,12 +10,12 @@ const PALETTE_BACKGROUND: MemoryMapped1DArray = unsafe { MemoryMapped1DArray::new(0x0500_0000) }; #[cfg(debug_assertions)] -const unsafe fn debug_unreachable_unchecked() -> ! { - unreachable!(); +unsafe fn debug_unreachable_unchecked(message: &'static str) -> ! { + unreachable!(message); } #[cfg(not(debug_assertions))] -const unsafe fn debug_unreachable_unchecked() -> ! { +const unsafe fn debug_unreachable_unchecked(message: &'static str) -> ! { use core::hint::unreachable_unchecked; unreachable_unchecked(); @@ -88,7 +88,7 @@ impl VRamState { if let VRamState::ReferenceCounted(count, _) = self { *count += 1; } else { - unsafe { debug_unreachable_unchecked() }; + unsafe { debug_unreachable_unchecked("Cannot increase reference count of free item") }; } } @@ -97,7 +97,7 @@ impl VRamState { *count -= 1; (*count, *tile_ref) } else { - unsafe { debug_unreachable_unchecked() }; + unsafe { debug_unreachable_unchecked("Cannot decrease reference count of free item") }; } } } @@ -151,7 +151,7 @@ impl<'a> VRamManager<'a> { self.tilesets[ptr] = tileset; ptr } - _ => unsafe { debug_unreachable_unchecked() }, + _ => unsafe { debug_unreachable_unchecked("Free pointer cannot point to data") }, } } else { self.tilesets.push(tileset); @@ -183,7 +183,7 @@ impl<'a> VRamManager<'a> { self.free_pointer = Some(tile_set_ref.id as usize); } - _ => unsafe { debug_unreachable_unchecked() }, + _ => panic!("Must remove valid tileset"), } } @@ -206,7 +206,9 @@ impl<'a> VRamManager<'a> { self.vram_free_pointer = Some(next_free as usize); } } - VRamState::ReferenceCounted(_, _) => unsafe { debug_unreachable_unchecked() }, + VRamState::ReferenceCounted(_, _) => unsafe { + debug_unreachable_unchecked("Free pointer must point to free item") + }, } self.references[ptr] = VRamState::ReferenceCounted(1, tile_ref); @@ -228,7 +230,7 @@ impl<'a> VRamManager<'a> { let tile_offset = (tile as usize) * data.format.tile_size() / 4; &data.tiles[tile_offset..(tile_offset + data.format.tile_size() / 4)] } else { - unsafe { debug_unreachable_unchecked() }; + panic!("Tile set ref must point to existing tile set"); }; let tile_size_in_half_words = TileFormat::FourBpp.tile_size() / 2; diff --git a/examples/the-hat-chooses-the-wizard/Cargo.lock b/examples/the-hat-chooses-the-wizard/Cargo.lock index c6a6fad7..5b924d8d 100644 --- a/examples/the-hat-chooses-the-wizard/Cargo.lock +++ b/examples/the-hat-chooses-the-wizard/Cargo.lock @@ -24,8 +24,6 @@ dependencies = [ "agb_sound_converter", "bare-metal", "bitflags", - "hashbrown", - "rustc-hash", ] [[package]] @@ -67,17 +65,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -149,15 +136,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" -dependencies = [ - "ahash", -] - [[package]] name = "hound" version = "3.4.0" @@ -241,12 +219,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" - [[package]] name = "png" version = "0.17.5" @@ -313,12 +285,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "ryu" version = "1.0.9" @@ -391,12 +357,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/examples/the-purple-night/Cargo.lock b/examples/the-purple-night/Cargo.lock index 49150aff..cbb2dcc7 100644 --- a/examples/the-purple-night/Cargo.lock +++ b/examples/the-purple-night/Cargo.lock @@ -24,8 +24,6 @@ dependencies = [ "agb_sound_converter", "bare-metal", "bitflags", - "hashbrown", - "rustc-hash", ] [[package]] @@ -67,17 +65,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -173,15 +160,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" -dependencies = [ - "ahash", -] - [[package]] name = "hound" version = "3.4.0" @@ -271,12 +249,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" - [[package]] name = "png" version = "0.17.5" @@ -349,12 +321,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "serde" version = "1.0.136" @@ -428,12 +394,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1"