taiko: micro optimizations

This commit is contained in:
MaxOhn
2021-04-29 01:33:08 +02:00
parent 2c913d5f3b
commit 9f984ac4e2
7 changed files with 103 additions and 51 deletions
+8 -18
View File
@@ -1,3 +1,9 @@
#[cfg(any(
feature = "fruits",
all(feature = "osu", not(feature = "no_sliders_no_leniency"))
))]
use crate::math_util;
mod attributes;
mod control_point;
mod error;
@@ -458,7 +464,7 @@ macro_rules! parse_hitobjects_body {
match path_type {
PathType::Linear if curve_points.len() % 2 == 0 => {
// Assert that the points are of the form A|B|B|C|C|E
if valid_linear(&curve_points) {
if math_util::valid_linear(&curve_points) {
for i in (2..curve_points.len() - 1).rev().step_by(2) {
curve_points.remove(i);
}
@@ -467,7 +473,7 @@ macro_rules! parse_hitobjects_body {
}
}
PathType::PerfectCurve if curve_points.len() == 3 => {
if is_linear(curve_points[0], curve_points[1], curve_points[2]) {
if math_util::is_linear(curve_points[0], curve_points[1], curve_points[2]) {
path_type = PathType::Linear;
}
},
@@ -775,22 +781,6 @@ fn split_colon(line: &str) -> Option<(&str, &str)> {
Some((split.next()?, split.next()?.trim()))
}
#[inline]
fn valid_linear(points: &[Pos2]) -> bool {
for i in (1..points.len() - 1).step_by(2) {
if points[i] != points[i + 1] {
return false;
}
}
true
}
#[inline]
fn is_linear(p0: Pos2, p1: Pos2, p2: Pos2) -> bool {
((p1.y - p0.y) * (p2.x - p0.x) - (p1.x - p0.x) * (p2.y - p0.y)).abs() <= f32::EPSILON
}
/// The type of curve of a slider.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PathType {