From 95f4a4c60cbd75645b0b57db62e3f4d8558ded04 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Wed, 8 Jul 2020 23:55:04 +0200 Subject: [PATCH] Deduplicate bitflags/bitarray_to_byte --- src/osu/beatmap.rs | 13 ++----------- src/utils.rs | 2 -- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/osu/beatmap.rs b/src/osu/beatmap.rs index eae0ac6..c4f0517 100644 --- a/src/osu/beatmap.rs +++ b/src/osu/beatmap.rs @@ -14,15 +14,6 @@ pub type SampleIndex = u16; pub type Time = u32; -// Helper functions -fn bitflags(flags: [bool; 8]) -> u8 { - let mut value = 0u8; - for (i, flag) in flags.iter().enumerate() { - value += ((0b1 as u8) << i) * (*flag as u8) as u8; - } - value -} - fn assemble_hit_object_type(hit_object_type: u8, new_combo: bool, skip_combo_colours: U3) -> u8 { let hit_object_type = 1u8 << hit_object_type; let new_combo = if new_combo { 0b0000_0010_u8 } else { 0u8 }; @@ -255,7 +246,7 @@ impl fmt::Display for TimingPointEffects { write!( f, "{}", - bitflags([ + utils::bitarray_to_byte([ self.kiai_time, false, false, @@ -360,7 +351,7 @@ impl fmt::Display for HitSound { write!( f, "{}", - bitflags([ + utils::bitarray_to_byte([ self.normal, self.whistle, self.finish, diff --git a/src/utils.rs b/src/utils.rs index e227615..de47917 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,8 +12,6 @@ pub fn byte_to_bitarray(byte: u8) -> [bool; 8] { bitarray } -#[allow(dead_code)] -/// Used to test `byte_to_bitarray` pub fn bitarray_to_byte(bitarray: [bool; 8]) -> u8 { bitarray .iter()