use proper default capacities

This commit is contained in:
MaxOhn
2024-02-13 15:11:30 +01:00
parent 2327287a32
commit b88e49889b
8 changed files with 43 additions and 19 deletions
+13 -2
View File
@@ -23,11 +23,22 @@ pub trait ISkill {
type DifficultyObjects<'a>: ?Sized; type DifficultyObjects<'a>: ?Sized;
} }
#[derive(Clone, Default)] #[derive(Clone)]
pub struct StrainSkill { pub struct StrainSkill {
pub curr_section_peak: f64, pub curr_section_peak: f64,
pub curr_section_end: f64, pub curr_section_end: f64,
pub strain_peaks: Vec<f64>, // TODO: default capacity pub strain_peaks: Vec<f64>,
}
impl Default for StrainSkill {
fn default() -> Self {
Self {
curr_section_peak: 0.0,
curr_section_end: 0.0,
// mean=386.81 | median=279
strain_peaks: Vec::with_capacity(256),
}
}
} }
impl StrainSkill { impl StrainSkill {
+6 -4
View File
@@ -46,13 +46,15 @@ pub fn convert_objects(
hr: bool, hr: bool,
cs: f32, cs: f32,
) -> Vec<PalpableObject> { ) -> Vec<PalpableObject> {
// TODO: check for better default capacity // mean=686.54 | median=501
let mut palpable_objects = Vec::with_capacity(converted.map.hit_objects.len() * 2); let mut palpable_objects = Vec::with_capacity(512);
let mut bufs = JuiceStreamBufs { let mut bufs = JuiceStreamBufs {
curve: CurveBuffers::default(), curve: CurveBuffers::default(),
nested_objects: Vec::new(), // TODO: default capacity // mean=31.65 | median=16
ticks: Vec::new(), // TODO: default capacity nested_objects: Vec::with_capacity(16),
// mean=5.21 | median=4
ticks: Vec::new(),
}; };
let mut rng = Random::new(RNG_SEED); let mut rng = Random::new(RNG_SEED);
+2 -3
View File
@@ -77,9 +77,8 @@ fn convert(map: &mut Beatmap) {
let mut last_values = PrevValues::default(); let mut last_values = PrevValues::default();
let mut curve_bufs = CurveBuffers::default(); let mut curve_bufs = CurveBuffers::default();
// TODO: find proper default // mean=668.7 | median=512
let capacity = map.hit_objects.len() * 2; let mut new_hit_objects = Vec::with_capacity(512);
let mut new_hit_objects = Vec::with_capacity(capacity);
for (obj, sound) in map.hit_objects.iter().zip(map.hit_sounds.iter().copied()) { for (obj, sound) in map.hit_objects.iter().zip(map.hit_sounds.iter().copied()) {
match obj.kind { match obj.kind {
+6 -3
View File
@@ -259,9 +259,12 @@ impl DecodeState for BeatmapState {
pending_timing_point: None, pending_timing_point: None,
pending_difficulty_point: None, pending_difficulty_point: None,
pending_effect_point: None, pending_effect_point: None,
curve_points: Vec::new(), // TODO: check for default size // mean=13.11 | median=8
vertices: Vec::new(), // TODO: check for default size curve_points: Vec::with_capacity(8),
point_split: Vec::new(), // TODO: check for default size // mean=16.27 | median=8
vertices: Vec::with_capacity(8),
// mean=19.97 | median=8
point_split: Vec::with_capacity(8),
} }
} }
} }
+2 -1
View File
@@ -34,7 +34,8 @@ pub fn convert_objects(
attrs: &mut OsuDifficultyAttributes, attrs: &mut OsuDifficultyAttributes,
) -> Vec<OsuObject> { ) -> Vec<OsuObject> {
let mut curve_bufs = CurveBuffers::default(); let mut curve_bufs = CurveBuffers::default();
let mut ticks_buf = Vec::new(); // TODO: default capacity // mean=5.16 | median=4
let mut ticks_buf = Vec::new();
let mut osu_objects: Vec<_> = converted let mut osu_objects: Vec<_> = converted
.map .map
+2 -1
View File
@@ -29,7 +29,8 @@ impl Speed {
Self { Self {
curr_strain: 0.0, curr_strain: 0.0,
curr_rhythm: 0.0, curr_rhythm: 0.0,
object_strains: Vec::new(), // TODO: default capacity // mean=406.72 | median=307
object_strains: Vec::with_capacity(256),
hit_window, hit_window,
inner: OsuStrainSkill::default(), inner: OsuStrainSkill::default(),
} }
+6 -3
View File
@@ -92,9 +92,12 @@ impl TaikoDifficultyObjects {
pub fn with_capacity(capacity: usize) -> Self { pub fn with_capacity(capacity: usize) -> Self {
Self { Self {
objects: Vec::with_capacity(capacity), objects: Vec::with_capacity(capacity),
center_hit_objects: Vec::default(), // TODO: default capacity // mean=301.7 | median=215
rim_hit_objects: Vec::default(), // TODO: default capacity center_hit_objects: Vec::with_capacity(256),
note_objects: Vec::default(), // TODO: default capacity // mean=309.21 | median=229
rim_hit_objects: Vec::with_capacity(256),
// mean=610.91 | median=466
note_objects: Vec::with_capacity(256),
} }
} }
+6 -2
View File
@@ -46,12 +46,16 @@ impl Peaks {
} }
pub fn difficulty_value(self) -> f64 { pub fn difficulty_value(self) -> f64 {
let mut peaks = Vec::new(); // TODO: default capacity
let color_peaks = self.color.get_curr_strain_peaks(); let color_peaks = self.color.get_curr_strain_peaks();
let rhythm_peaks = self.rhythm.get_curr_strain_peaks(); let rhythm_peaks = self.rhythm.get_curr_strain_peaks();
let stamina_peaks = self.stamina.get_curr_strain_peaks(); let stamina_peaks = self.stamina.get_curr_strain_peaks();
let cap = color_peaks
.len()
.min(rhythm_peaks.len())
.min(stamina_peaks.len());
let mut peaks = Vec::with_capacity(cap);
let zip = color_peaks let zip = color_peaks
.iter() .iter()
.copied() .copied()