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

@ -50,12 +50,14 @@ impl<N: Clone> vec::Vec0<N> {
} }
impl<N> Iterable<N> for vec::Vec0<N> { impl<N> Iterable<N> for vec::Vec0<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> { fn iter<'l>(&'l self) -> VecIterator<'l, N> {
unsafe { cast::transmute::<&'l vec::Vec0<N>, &'l [N, ..0]>(self).iter() } 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> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { 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() } unsafe { cast::transmute::<&'l mut vec::Vec0<N>, &'l mut [N, ..0]>(self).mut_iter() }
} }
@ -69,8 +71,10 @@ impl<N> Dim for vec::Vec0<N> {
} }
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N> { impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N> {
#[inline(always)]
pub fn canonical_basis(_: &fn(vec::Vec0<N>)) { } pub fn canonical_basis(_: &fn(vec::Vec0<N>)) { }
#[inline(always)]
pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>)) { } pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>)) { }
} }
@ -228,6 +232,7 @@ impl<N: Clone + One> One for vec::Vec0<N> {
} }
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for vec::Vec0<N> { impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for vec::Vec0<N> {
#[inline]
fn from_iterator(_: &mut Iter) -> vec::Vec0<N> { fn from_iterator(_: &mut Iter) -> 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)