mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
util: Inline trivial range constructors.
These were showing up in the profile.
This commit is contained in:
parent
432087c0ea
commit
6f2aa54120
1 changed files with 12 additions and 0 deletions
|
@ -22,15 +22,23 @@ pub trait Int:
|
||||||
fn from_usize(n: usize) -> Option<Self>;
|
fn from_usize(n: usize) -> Option<Self>;
|
||||||
}
|
}
|
||||||
impl Int for isize {
|
impl Int for isize {
|
||||||
|
#[inline]
|
||||||
fn zero() -> isize { 0 }
|
fn zero() -> isize { 0 }
|
||||||
|
#[inline]
|
||||||
fn one() -> isize { 1 }
|
fn one() -> isize { 1 }
|
||||||
|
#[inline]
|
||||||
fn max_value() -> isize { ::std::isize::MAX }
|
fn max_value() -> isize { ::std::isize::MAX }
|
||||||
|
#[inline]
|
||||||
fn from_usize(n: usize) -> Option<isize> { num_lib::NumCast::from(n) }
|
fn from_usize(n: usize) -> Option<isize> { num_lib::NumCast::from(n) }
|
||||||
}
|
}
|
||||||
impl Int for usize {
|
impl Int for usize {
|
||||||
|
#[inline]
|
||||||
fn zero() -> usize { 0 }
|
fn zero() -> usize { 0 }
|
||||||
|
#[inline]
|
||||||
fn one() -> usize { 1 }
|
fn one() -> usize { 1 }
|
||||||
|
#[inline]
|
||||||
fn max_value() -> usize { ::std::usize::MAX }
|
fn max_value() -> usize { ::std::usize::MAX }
|
||||||
|
#[inline]
|
||||||
fn from_usize(n: usize) -> Option<usize> { Some(n) }
|
fn from_usize(n: usize) -> Option<usize> { Some(n) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +96,13 @@ macro_rules! int_range_index {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $crate::range::Int for $Self_ {
|
impl $crate::range::Int for $Self_ {
|
||||||
|
#[inline]
|
||||||
fn zero() -> $Self_ { $Self_($crate::range::Int::zero()) }
|
fn zero() -> $Self_ { $Self_($crate::range::Int::zero()) }
|
||||||
|
#[inline]
|
||||||
fn one() -> $Self_ { $Self_($crate::range::Int::one()) }
|
fn one() -> $Self_ { $Self_($crate::range::Int::one()) }
|
||||||
|
#[inline]
|
||||||
fn max_value() -> $Self_ { $Self_($crate::range::Int::max_value()) }
|
fn max_value() -> $Self_ { $Self_($crate::range::Int::max_value()) }
|
||||||
|
#[inline]
|
||||||
fn from_usize(n: usize) -> Option<$Self_> { $crate::range::Int::from_usize(n).map($Self_) }
|
fn from_usize(n: usize) -> Option<$Self_> { $crate::range::Int::from_usize(n).map($Self_) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue