From 84fef8a87fb25c229a7586572cc17bdccfe7ffc2 Mon Sep 17 00:00:00 2001 From: RustyNixieTube <49496554+RustyNixieTube@users.noreply.github.com> Date: Sat, 19 Jun 2021 18:47:42 +0200 Subject: [PATCH] Add comment to STORAGE_SIZE and simplify it (#223) * Add comment to STORAGE_SIZE and simplify it * Modify comment Co-authored-by: RustyNixieTube --- core/editor/src/input/keyboard.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/editor/src/input/keyboard.rs b/core/editor/src/input/keyboard.rs index ca9e2fd5d..113991d60 100644 --- a/core/editor/src/input/keyboard.rs +++ b/core/editor/src/input/keyboard.rs @@ -2,7 +2,9 @@ pub const NUMBER_OF_KEYS: usize = Key::NumKeys as usize; // Edit this to specify the storage type used // TODO: Increase size of type pub type StorageType = u128; -const STORAGE_SIZE: u32 = std::mem::size_of::() as u32 * 8 + 2 - std::mem::size_of::().leading_zeros(); + +// base 2 logarithm of the storage type used to represents how many bits you need to fully address every bit in that storage type +const STORAGE_SIZE: u32 = (std::mem::size_of::() * 8).trailing_zeros(); const STORAGE_SIZE_BITS: usize = 1 << STORAGE_SIZE; const KEY_MASK_STORAGE_LENGTH: usize = (NUMBER_OF_KEYS + STORAGE_SIZE_BITS - 1) >> STORAGE_SIZE; pub type KeyStates = BitVector;