From 939a97f5cb4c8f44bc60784bbf4aa5d44f1c5dca Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 18 Apr 2013 23:24:24 +1000 Subject: [PATCH] Add #[inline(always)] to each operator method --- src/libcore/num/f32.rs | 6 ++++++ src/libcore/num/f64.rs | 6 ++++++ src/libcore/num/float.rs | 12 ++++++++++++ src/libcore/num/int-template.rs | 13 +++++++++++++ src/libcore/num/uint-template.rs | 13 +++++++++++++ 5 files changed, 50 insertions(+) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 5e672ea0dfa8..404f1a82de5d 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -288,26 +288,32 @@ impl num::One for f32 { #[cfg(notest)] impl ops::Add for f32 { + #[inline(always)] fn add(&self, other: &f32) -> f32 { *self + *other } } #[cfg(notest)] impl ops::Sub for f32 { + #[inline(always)] fn sub(&self, other: &f32) -> f32 { *self - *other } } #[cfg(notest)] impl ops::Mul for f32 { + #[inline(always)] fn mul(&self, other: &f32) -> f32 { *self * *other } } #[cfg(notest)] impl ops::Div for f32 { + #[inline(always)] fn div(&self, other: &f32) -> f32 { *self / *other } } #[cfg(notest)] impl ops::Modulo for f32 { + #[inline(always)] fn modulo(&self, other: &f32) -> f32 { *self % *other } } #[cfg(notest)] impl ops::Neg for f32 { + #[inline(always)] fn neg(&self) -> f32 { -*self } } diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 4c96da73d213..b4eaa0e7fdc6 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -310,26 +310,32 @@ impl num::One for f64 { #[cfg(notest)] impl ops::Add for f64 { + #[inline(always)] fn add(&self, other: &f64) -> f64 { *self + *other } } #[cfg(notest)] impl ops::Sub for f64 { + #[inline(always)] fn sub(&self, other: &f64) -> f64 { *self - *other } } #[cfg(notest)] impl ops::Mul for f64 { + #[inline(always)] fn mul(&self, other: &f64) -> f64 { *self * *other } } #[cfg(notest)] impl ops::Div for f64 { + #[inline(always)] fn div(&self, other: &f64) -> f64 { *self / *other } } #[cfg(notest)] impl ops::Modulo for f64 { + #[inline(always)] fn modulo(&self, other: &f64) -> f64 { *self % *other } } #[cfg(notest)] impl ops::Neg for f64 { + #[inline(always)] fn neg(&self) -> f64 { -*self } } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 488756787b5c..42f0f033ac24 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -387,15 +387,21 @@ pub fn tan(x: float) -> float { #[cfg(notest)] impl Eq for float { + #[inline(always)] fn eq(&self, other: &float) -> bool { (*self) == (*other) } + #[inline(always)] fn ne(&self, other: &float) -> bool { (*self) != (*other) } } #[cfg(notest)] impl Ord for float { + #[inline(always)] fn lt(&self, other: &float) -> bool { (*self) < (*other) } + #[inline(always)] fn le(&self, other: &float) -> bool { (*self) <= (*other) } + #[inline(always)] fn ge(&self, other: &float) -> bool { (*self) >= (*other) } + #[inline(always)] fn gt(&self, other: &float) -> bool { (*self) > (*other) } } @@ -444,26 +450,32 @@ impl num::Round for float { #[cfg(notest)] impl ops::Add for float { + #[inline(always)] fn add(&self, other: &float) -> float { *self + *other } } #[cfg(notest)] impl ops::Sub for float { + #[inline(always)] fn sub(&self, other: &float) -> float { *self - *other } } #[cfg(notest)] impl ops::Mul for float { + #[inline(always)] fn mul(&self, other: &float) -> float { *self * *other } } #[cfg(notest)] impl ops::Div for float { + #[inline(always)] fn div(&self, other: &float) -> float { *self / *other } } #[cfg(notest)] impl ops::Modulo for float { + #[inline(always)] fn modulo(&self, other: &float) -> float { *self % *other } } #[cfg(notest)] impl ops::Neg for float { + #[inline(always)] fn neg(&self) -> float { -*self } } diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index f901e5910274..044c62e92c17 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -177,50 +177,63 @@ impl num::One for T { #[cfg(notest)] impl ops::Add for T { + #[inline(always)] fn add(&self, other: &T) -> T { *self + *other } } #[cfg(notest)] impl ops::Sub for T { + #[inline(always)] fn sub(&self, other: &T) -> T { *self - *other } } #[cfg(notest)] impl ops::Mul for T { + #[inline(always)] fn mul(&self, other: &T) -> T { *self * *other } } #[cfg(notest)] impl ops::Div for T { + #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } #[cfg(notest)] impl ops::Modulo for T { + #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } #[cfg(notest)] impl ops::Neg for T { + #[inline(always)] fn neg(&self) -> T { -*self } } + #[cfg(notest)] impl ops::BitOr for T { + #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } #[cfg(notest)] impl ops::BitAnd for T { + #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } #[cfg(notest)] impl ops::BitXor for T { + #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } #[cfg(notest)] impl ops::Shl for T { + #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } #[cfg(notest)] impl ops::Shr for T { + #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } #[cfg(notest)] impl ops::Not for T { + #[inline(always)] fn not(&self) -> T { !*self } } diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 34c11804af43..b49ec65a95bb 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -142,50 +142,63 @@ impl num::One for T { #[cfg(notest)] impl ops::Add for T { + #[inline(always)] fn add(&self, other: &T) -> T { *self + *other } } #[cfg(notest)] impl ops::Sub for T { + #[inline(always)] fn sub(&self, other: &T) -> T { *self - *other } } #[cfg(notest)] impl ops::Mul for T { + #[inline(always)] fn mul(&self, other: &T) -> T { *self * *other } } #[cfg(notest)] impl ops::Div for T { + #[inline(always)] fn div(&self, other: &T) -> T { *self / *other } } #[cfg(notest)] impl ops::Modulo for T { + #[inline(always)] fn modulo(&self, other: &T) -> T { *self % *other } } #[cfg(notest)] impl ops::Neg for T { + #[inline(always)] fn neg(&self) -> T { -*self } } + #[cfg(notest)] impl ops::BitOr for T { + #[inline(always)] fn bitor(&self, other: &T) -> T { *self | *other } } #[cfg(notest)] impl ops::BitAnd for T { + #[inline(always)] fn bitand(&self, other: &T) -> T { *self & *other } } #[cfg(notest)] impl ops::BitXor for T { + #[inline(always)] fn bitxor(&self, other: &T) -> T { *self ^ *other } } #[cfg(notest)] impl ops::Shl for T { + #[inline(always)] fn shl(&self, other: &T) -> T { *self << *other } } #[cfg(notest)] impl ops::Shr for T { + #[inline(always)] fn shr(&self, other: &T) -> T { *self >> *other } } #[cfg(notest)] impl ops::Not for T { + #[inline(always)] fn not(&self) -> T { !*self } }