Skip to content

Commit

Permalink
perf!: store HitObjectKind::Slider fields in Box (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn authored Nov 10, 2023
1 parent b6b97c1 commit f8c246b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- __Breaking adjustments:__
- Removed the method `HitObject::end_time` from the public api.
- The fields `control_points` and `edge_sounds` of `HitObjectKind::Slider` are now stored in a `Box` rather than a `Vec`.
- Overhauled gradual calculation. All relevant types are now gated behind the `gradual` feature which must be enabled.
- `*GradualDifficultyAttributes` has been renamed to `*GradualDifficulty` and `*GradualPerformanceAttributes`
has been renamed to `*GradualPerformance`.
Expand Down
4 changes: 2 additions & 2 deletions src/parse/hitobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub enum HitObjectKind {
/// The amount of repeat points of the slider.
repeats: usize,
/// The control points of the slider.
control_points: Vec<PathControlPoint>,
control_points: Box<[PathControlPoint]>,
/// Sample sounds for the slider head, end, and repeat points.
/// Required for converts.
edge_sounds: Vec<u8>,
edge_sounds: Box<[u8]>,
},
/// A spinner object.
Spinner {
Expand Down
10 changes: 5 additions & 5 deletions src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ macro_rules! parse_hitobjects_body {
// the actual `&str` elements transmuted into `(usize, usize)`.
let mut point_split_raw: Vec<(usize, usize)> = Vec::new();

// Buffer to re-use for all sliders
// Buffers to re-use for all sliders
let mut vertices = Vec::new();
let mut control_points = Vec::new();

'next_line: while next_line!($reader)? != 0 {
if let Some(bytes) = $reader.get_section() {
Expand Down Expand Up @@ -482,8 +483,7 @@ macro_rules! parse_hitobjects_body {
} else if kind & Self::SLIDER_FLAG > 0 {
$self.n_sliders += 1;

// Control Points: [1, 94872] | Median=3 | Mean=2.9984
let mut control_points = Vec::with_capacity(3);
control_points.clear();

let control_point_iter = match split.next() {
Some(s) => s.split('|'),
Expand Down Expand Up @@ -569,7 +569,7 @@ macro_rules! parse_hitobjects_body {
None => None,
};

let mut edge_sounds = vec![sound; repeats + 2];
let mut edge_sounds = vec![sound; repeats + 2].into_boxed_slice();

split
.next()
Expand All @@ -590,7 +590,7 @@ macro_rules! parse_hitobjects_body {
HitObjectKind::Slider {
repeats,
pixel_len,
control_points,
control_points: Box::from(control_points.as_slice()),
edge_sounds,
}
}
Expand Down

0 comments on commit f8c246b

Please sign in to comment.