1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Optimize: add #[inline(always)] to various low-level things

saves up to 20% (text tesselation), and at least 5% overall
This commit is contained in:
Emil Ernerfeldt
2021-03-28 23:16:19 +02:00
parent ccc501f302
commit 46425f1e38
10 changed files with 144 additions and 7 deletions

View File

@@ -92,11 +92,13 @@ pub trait One {
fn one() -> Self;
}
impl One for f32 {
#[inline(always)]
fn one() -> Self {
1.0
}
}
impl One for f64 {
#[inline(always)]
fn one() -> Self {
1.0
}
@@ -121,6 +123,7 @@ impl Real for f64 {}
// ----------------------------------------------------------------------------
/// Linear interpolation.
#[inline(always)]
pub fn lerp<R, T>(range: RangeInclusive<R>, t: T) -> R
where
T: Real + Mul<R, Output = R>,
@@ -309,9 +312,11 @@ pub trait NumExt {
macro_rules! impl_num_ext {
($t: ty) => {
impl NumExt for $t {
#[inline(always)]
fn at_least(self, lower_limit: Self) -> Self {
self.max(lower_limit)
}
#[inline(always)]
fn at_most(self, upper_limit: Self) -> Self {
self.min(upper_limit)
}