Add missing #[inline] hints.

This commit is contained in:
Sébastien Crozet 2013-08-07 20:53:51 +02:00
parent efd14f9e88
commit 50a6454ae8
5 changed files with 184 additions and 162 deletions

View File

@ -28,6 +28,7 @@ macro_rules! mat_cast_impl(
macro_rules! iterable_impl( macro_rules! iterable_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Iterable<N> for $t<N> { impl<N> Iterable<N> for $t<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> { fn iter<'l>(&'l self) -> VecIterator<'l, N> {
unsafe { unsafe {
cast::transmute::<&'l $t<N>, &'l [N, ..$dim * $dim]>(self).iter() cast::transmute::<&'l $t<N>, &'l [N, ..$dim * $dim]>(self).iter()
@ -40,6 +41,7 @@ macro_rules! iterable_impl(
macro_rules! iterable_mut_impl( macro_rules! iterable_mut_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> IterableMut<N> for $t<N> { impl<N> IterableMut<N> for $t<N> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
unsafe { unsafe {
cast::transmute::<&'l mut $t<N>, &'l mut [N, ..$dim * $dim]>(self).mut_iter() cast::transmute::<&'l mut $t<N>, &'l mut [N, ..$dim * $dim]>(self).mut_iter()
@ -103,6 +105,7 @@ macro_rules! indexable_impl(
macro_rules! column_impl( macro_rules! column_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N: Clone, V: Zero + Iterable<N> + IterableMut<N>> Column<V> for $t<N> { impl<N: Clone, V: Zero + Iterable<N> + IterableMut<N>> Column<V> for $t<N> {
#[inline]
fn set_column(&mut self, col: uint, v: V) { fn set_column(&mut self, col: uint, v: V) {
for (i, e) in v.iter().enumerate() { for (i, e) in v.iter().enumerate() {
if i == Dim::dim::<$t<N>>() { if i == Dim::dim::<$t<N>>() {
@ -113,6 +116,7 @@ macro_rules! column_impl(
} }
} }
#[inline]
fn column(&self, col: uint) -> V { fn column(&self, col: uint) -> V {
let mut res = Zero::zero::<V>(); let mut res = Zero::zero::<V>();
@ -133,6 +137,7 @@ macro_rules! column_impl(
macro_rules! mul_impl( macro_rules! mul_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N: Clone + Ring> Mul<$t<N>, $t<N>> for $t<N> { impl<N: Clone + Ring> Mul<$t<N>, $t<N>> for $t<N> {
#[inline]
fn mul(&self, other: &$t<N>) -> $t<N> { fn mul(&self, other: &$t<N>) -> $t<N> {
let mut res: $t<N> = Zero::zero(); let mut res: $t<N> = Zero::zero();
@ -157,6 +162,7 @@ macro_rules! mul_impl(
macro_rules! rmul_impl( macro_rules! rmul_impl(
($t: ident, $v: ident, $dim: expr) => ( ($t: ident, $v: ident, $dim: expr) => (
impl<N: Clone + Ring> RMul<$v<N>> for $t<N> { impl<N: Clone + Ring> RMul<$v<N>> for $t<N> {
#[inline]
fn rmul(&self, other: &$v<N>) -> $v<N> { fn rmul(&self, other: &$v<N>) -> $v<N> {
let mut res : $v<N> = Zero::zero(); let mut res : $v<N> = Zero::zero();
@ -176,6 +182,7 @@ macro_rules! rmul_impl(
macro_rules! lmul_impl( macro_rules! lmul_impl(
($t: ident, $v: ident, $dim: expr) => ( ($t: ident, $v: ident, $dim: expr) => (
impl<N: Clone + Ring> LMul<$v<N>> for $t<N> { impl<N: Clone + Ring> LMul<$v<N>> for $t<N> {
#[inline]
fn lmul(&self, other: &$v<N>) -> $v<N> { fn lmul(&self, other: &$v<N>) -> $v<N> {
let mut res : $v<N> = Zero::zero(); let mut res : $v<N> = Zero::zero();
@ -309,6 +316,7 @@ macro_rules! transpose_impl(
res res
} }
#[inline]
fn transpose(&mut self) { fn transpose(&mut self) {
for i in range(1u, $dim) { for i in range(1u, $dim) {
for j in range(0u, i) { for j in range(0u, i) {
@ -352,6 +360,7 @@ macro_rules! approx_eq_impl(
macro_rules! to_homogeneous_impl( macro_rules! to_homogeneous_impl(
($t: ident, $t2: ident, $dim: expr, $dim2: expr) => ( ($t: ident, $t2: ident, $dim: expr, $dim2: expr) => (
impl<N: One + Zero + Clone> ToHomogeneous<$t2<N>> for $t<N> { impl<N: One + Zero + Clone> ToHomogeneous<$t2<N>> for $t<N> {
#[inline]
fn to_homogeneous(&self) -> $t2<N> { fn to_homogeneous(&self) -> $t2<N> {
let mut res: $t2<N> = One::one(); let mut res: $t2<N> = One::one();
@ -370,6 +379,7 @@ macro_rules! to_homogeneous_impl(
macro_rules! from_homogeneous_impl( macro_rules! from_homogeneous_impl(
($t: ident, $t2: ident, $dim: expr, $dim2: expr) => ( ($t: ident, $t2: ident, $dim: expr, $dim2: expr) => (
impl<N: One + Zero + Clone> FromHomogeneous<$t2<N>> for $t<N> { impl<N: One + Zero + Clone> FromHomogeneous<$t2<N>> for $t<N> {
#[inline]
fn from(m: &$t2<N>) -> $t<N> { fn from(m: &$t2<N>) -> $t<N> {
let mut res: $t<N> = One::one(); let mut res: $t<N> = One::one();

View File

@ -89,7 +89,7 @@ Inv for Mat3<N> {
} }
else { else {
*self = Mat3::new( *self = Mat3::new(
(minor_m12_m23 / det), (minor_m12_m23 / det),
((self.m13 * self.m32 - self.m33 * self.m12) / det), ((self.m13 * self.m32 - self.m33 * self.m12) / det),
((self.m12 * self.m23 - self.m22 * self.m13) / det), ((self.m12 * self.m23 - self.m22 * self.m13) / det),

View File

@ -17,230 +17,235 @@ use traits::indexable::Indexable;
use vec; use vec;
impl<N> vec::Vec0<N> { impl<N> vec::Vec0<N> {
/// Creates a new vector. /// Creates a new vector.
#[inline] #[inline]
pub fn new() -> vec::Vec0<N> { pub fn new() -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N: Clone> Indexable<uint, N> for vec::Vec0<N> { impl<N: Clone> Indexable<uint, N> for vec::Vec0<N> {
#[inline] #[inline]
pub fn at(&self, _: uint) -> N { pub fn at(&self, _: uint) -> N {
fail!("Cannot index a Vec0.") fail!("Cannot index a Vec0.")
} }
#[inline] #[inline]
pub fn set(&mut self, _: uint, _: N) { pub fn set(&mut self, _: uint, _: N) {
} }
#[inline] #[inline]
pub fn swap(&mut self, _: uint, _: uint) { pub fn swap(&mut self, _: uint, _: uint) {
} }
} }
impl<N: Clone> vec::Vec0<N> { impl<N: Clone> vec::Vec0<N> {
/// Creates a new vector. The parameter is not taken in account. /// Creates a new vector. The parameter is not taken in account.
#[inline] #[inline]
pub fn new_repeat(_: N) -> vec::Vec0<N> { pub fn new_repeat(_: N) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N> Iterable<N> for vec::Vec0<N> { impl<N> Iterable<N> for vec::Vec0<N> {
fn iter<'l>(&'l self) -> VecIterator<'l, N> { #[inline]
unsafe { cast::transmute::<&'l vec::Vec0<N>, &'l [N, ..0]>(self).iter() } fn iter<'l>(&'l self) -> VecIterator<'l, N> {
} unsafe { cast::transmute::<&'l vec::Vec0<N>, &'l [N, ..0]>(self).iter() }
}
} }
impl<N> IterableMut<N> for vec::Vec0<N> { impl<N> IterableMut<N> for vec::Vec0<N> {
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { #[inline]
unsafe { cast::transmute::<&'l mut vec::Vec0<N>, &'l mut [N, ..0]>(self).mut_iter() } fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
} unsafe { cast::transmute::<&'l mut vec::Vec0<N>, &'l mut [N, ..0]>(self).mut_iter() }
}
} }
impl<N> Dim for vec::Vec0<N> { impl<N> Dim for vec::Vec0<N> {
#[inline] #[inline]
fn dim() -> uint { fn dim() -> uint {
0 0
} }
} }
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N> { impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N> {
pub fn canonical_basis(_: &fn(vec::Vec0<N>)) { } #[inline(always)]
pub fn canonical_basis(_: &fn(vec::Vec0<N>)) { }
pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>)) { } #[inline(always)]
pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>)) { }
} }
impl<N: Clone + Add<N,N>> Add<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> { impl<N: Clone + Add<N,N>> Add<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
#[inline] #[inline]
fn add(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> { fn add(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N: Clone + Sub<N,N>> Sub<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> { impl<N: Clone + Sub<N,N>> Sub<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
#[inline] #[inline]
fn sub(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> { fn sub(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N: Neg<N>> Neg<vec::Vec0<N>> for vec::Vec0<N> { impl<N: Neg<N>> Neg<vec::Vec0<N>> for vec::Vec0<N> {
#[inline] #[inline]
fn neg(&self) -> vec::Vec0<N> { fn neg(&self) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N: Ring> Dot<N> for vec::Vec0<N> { impl<N: Ring> Dot<N> for vec::Vec0<N> {
#[inline] #[inline]
fn dot(&self, _: &vec::Vec0<N>) -> N { fn dot(&self, _: &vec::Vec0<N>) -> N {
Zero::zero() Zero::zero()
} }
} }
impl<N: Clone + Ring> SubDot<N> for vec::Vec0<N> { impl<N: Clone + Ring> SubDot<N> for vec::Vec0<N> {
#[inline] #[inline]
fn sub_dot(&self, _: &vec::Vec0<N>, _: &vec::Vec0<N>) -> N { fn sub_dot(&self, _: &vec::Vec0<N>, _: &vec::Vec0<N>) -> N {
Zero::zero() Zero::zero()
} }
} }
impl<N: Mul<N, N>> ScalarMul<N> for vec::Vec0<N> { impl<N: Mul<N, N>> ScalarMul<N> for vec::Vec0<N> {
#[inline] #[inline]
fn scalar_mul(&self, _: &N) -> vec::Vec0<N> { fn scalar_mul(&self, _: &N) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
#[inline] #[inline]
fn scalar_mul_inplace(&mut self, _: &N) { } fn scalar_mul_inplace(&mut self, _: &N) { }
} }
impl<N: Div<N, N>> ScalarDiv<N> for vec::Vec0<N> { impl<N: Div<N, N>> ScalarDiv<N> for vec::Vec0<N> {
#[inline] #[inline]
fn scalar_div(&self, _: &N) -> vec::Vec0<N> { fn scalar_div(&self, _: &N) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
#[inline] #[inline]
fn scalar_div_inplace(&mut self, _: &N) { } fn scalar_div_inplace(&mut self, _: &N) { }
} }
impl<N: Add<N, N>> ScalarAdd<N> for vec::Vec0<N> { impl<N: Add<N, N>> ScalarAdd<N> for vec::Vec0<N> {
#[inline] #[inline]
fn scalar_add(&self, _: &N) -> vec::Vec0<N> { fn scalar_add(&self, _: &N) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
#[inline] #[inline]
fn scalar_add_inplace(&mut self, _: &N) { } fn scalar_add_inplace(&mut self, _: &N) { }
} }
impl<N: Sub<N, N>> ScalarSub<N> for vec::Vec0<N> { impl<N: Sub<N, N>> ScalarSub<N> for vec::Vec0<N> {
#[inline] #[inline]
fn scalar_sub(&self, _: &N) -> vec::Vec0<N> { fn scalar_sub(&self, _: &N) -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
#[inline] #[inline]
fn scalar_sub_inplace(&mut self, _: &N) { } fn scalar_sub_inplace(&mut self, _: &N) { }
} }
impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> { impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
#[inline] #[inline]
fn translation(&self) -> vec::Vec0<N> { fn translation(&self) -> vec::Vec0<N> {
self.clone() self.clone()
} }
#[inline] #[inline]
fn inv_translation(&self) -> vec::Vec0<N> { fn inv_translation(&self) -> vec::Vec0<N> {
-self -self
} }
#[inline] #[inline]
fn translate_by(&mut self, t: &vec::Vec0<N>) { fn translate_by(&mut self, t: &vec::Vec0<N>) {
*self = *self + *t; *self = *self + *t;
} }
} }
impl<N: Add<N, N> + Neg<N> + Clone> Translatable<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> { impl<N: Add<N, N> + Neg<N> + Clone> Translatable<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
#[inline] #[inline]
fn translated(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> { fn translated(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
self + *t self + *t
} }
} }
impl<N: Clone + DivisionRing + Algebraic> Norm<N> for vec::Vec0<N> { impl<N: Clone + DivisionRing + Algebraic> Norm<N> for vec::Vec0<N> {
#[inline] #[inline]
fn sqnorm(&self) -> N { fn sqnorm(&self) -> N {
self.dot(self) self.dot(self)
} }
#[inline] #[inline]
fn norm(&self) -> N { fn norm(&self) -> N {
self.sqnorm().sqrt() self.sqnorm().sqrt()
} }
#[inline] #[inline]
fn normalized(&self) -> vec::Vec0<N> { fn normalized(&self) -> vec::Vec0<N> {
let mut res : vec::Vec0<N> = self.clone(); let mut res : vec::Vec0<N> = self.clone();
res.normalize(); res.normalize();
res res
} }
#[inline] #[inline]
fn normalize(&mut self) -> N { fn normalize(&mut self) -> N {
let l = self.norm(); let l = self.norm();
self.scalar_div_inplace(&l); self.scalar_div_inplace(&l);
l l
} }
} }
impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> { impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
#[inline] #[inline]
fn approx_epsilon() -> N { fn approx_epsilon() -> N {
ApproxEq::approx_epsilon::<N, N>() ApproxEq::approx_epsilon::<N, N>()
} }
#[inline] #[inline]
fn approx_eq(&self, _: &vec::Vec0<N>) -> bool { fn approx_eq(&self, _: &vec::Vec0<N>) -> bool {
true true
} }
#[inline] #[inline]
fn approx_eq_eps(&self, _: &vec::Vec0<N>, _: &N) -> bool { fn approx_eq_eps(&self, _: &vec::Vec0<N>, _: &N) -> bool {
true true
} }
} }
impl<N: Clone + One> One for vec::Vec0<N> { impl<N: Clone + One> One for vec::Vec0<N> {
#[inline] #[inline]
fn one() -> vec::Vec0<N> { fn one() -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for vec::Vec0<N> { impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for vec::Vec0<N> {
fn from_iterator(_: &mut Iter) -> vec::Vec0<N> { #[inline]
vec::Vec0 fn from_iterator(_: &mut Iter) -> vec::Vec0<N> {
} vec::Vec0
}
} }
impl<N: Bounded + Clone> Bounded for vec::Vec0<N> { impl<N: Bounded + Clone> Bounded for vec::Vec0<N> {
#[inline] #[inline]
fn max_value() -> vec::Vec0<N> { fn max_value() -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
#[inline] #[inline]
fn min_value() -> vec::Vec0<N> { fn min_value() -> vec::Vec0<N> {
vec::Vec0 vec::Vec0
} }
} }

View File

@ -147,6 +147,7 @@ macro_rules! new_repeat_impl(
macro_rules! iterable_impl( macro_rules! iterable_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Iterable<N> for $t<N> { impl<N> Iterable<N> for $t<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> { fn iter<'l>(&'l self) -> VecIterator<'l, N> {
unsafe { unsafe {
cast::transmute::<&'l $t<N>, &'l [N, ..$dim]>(self).iter() cast::transmute::<&'l $t<N>, &'l [N, ..$dim]>(self).iter()
@ -159,6 +160,7 @@ macro_rules! iterable_impl(
macro_rules! iterable_mut_impl( macro_rules! iterable_mut_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> IterableMut<N> for $t<N> { impl<N> IterableMut<N> for $t<N> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
unsafe { unsafe {
cast::transmute::<&'l mut $t<N>, &'l mut [N, ..$dim]>(self).mut_iter() cast::transmute::<&'l mut $t<N>, &'l mut [N, ..$dim]>(self).mut_iter()
@ -182,6 +184,7 @@ macro_rules! dim_impl(
macro_rules! basis_impl( macro_rules! basis_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for $t<N> { impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for $t<N> {
#[inline]
pub fn canonical_basis(f: &fn($t<N>)) { pub fn canonical_basis(f: &fn($t<N>)) {
for i in range(0u, $dim) { for i in range(0u, $dim) {
let mut basis_element : $t<N> = Zero::zero(); let mut basis_element : $t<N> = Zero::zero();
@ -192,6 +195,7 @@ macro_rules! basis_impl(
} }
} }
#[inline]
pub fn orthonormal_subspace_basis(&self, f: &fn($t<N>)) { pub fn orthonormal_subspace_basis(&self, f: &fn($t<N>)) {
// compute the basis of the orthogonal subspace using Gram-Schmidt // compute the basis of the orthogonal subspace using Gram-Schmidt
// orthogonalization algorithm // orthogonalization algorithm
@ -451,6 +455,7 @@ macro_rules! one_impl(
macro_rules! from_iterator_impl( macro_rules! from_iterator_impl(
($t: ident, $param0: ident $(, $paramN: ident)*) => ( ($t: ident, $param0: ident $(, $paramN: ident)*) => (
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for $t<N> { impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for $t<N> {
#[inline]
fn from_iterator($param0: &mut Iter) -> $t<N> { fn from_iterator($param0: &mut Iter) -> $t<N> {
$t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*)
} }

View File

@ -143,6 +143,7 @@ static SAMPLES_3_F64: [Vec3<f64>, ..42] = [
]; ];
impl UniformSphereSample for Vec2<f64> { impl UniformSphereSample for Vec2<f64> {
#[inline(always)]
pub fn sample(f: &fn(&'static Vec2<f64>)) { pub fn sample(f: &fn(&'static Vec2<f64>)) {
for sample in SAMPLES_2_F64.iter() { for sample in SAMPLES_2_F64.iter() {
f(sample) f(sample)
@ -151,6 +152,7 @@ impl UniformSphereSample for Vec2<f64> {
} }
impl UniformSphereSample for Vec3<f64> { impl UniformSphereSample for Vec3<f64> {
#[inline(always)]
pub fn sample(f: &fn(&'static Vec3<f64>)) { pub fn sample(f: &fn(&'static Vec3<f64>)) {
for sample in SAMPLES_3_F64.iter() { for sample in SAMPLES_3_F64.iter() {
f(sample) f(sample)