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(
($t: ident, $dim: expr) => (
impl<N> Iterable<N> for $t<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> {
unsafe {
cast::transmute::<&'l $t<N>, &'l [N, ..$dim * $dim]>(self).iter()
@ -40,6 +41,7 @@ macro_rules! iterable_impl(
macro_rules! iterable_mut_impl(
($t: ident, $dim: expr) => (
impl<N> IterableMut<N> for $t<N> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
unsafe {
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(
($t: ident, $dim: expr) => (
impl<N: Clone, V: Zero + Iterable<N> + IterableMut<N>> Column<V> for $t<N> {
#[inline]
fn set_column(&mut self, col: uint, v: V) {
for (i, e) in v.iter().enumerate() {
if i == Dim::dim::<$t<N>>() {
@ -113,6 +116,7 @@ macro_rules! column_impl(
}
}
#[inline]
fn column(&self, col: uint) -> V {
let mut res = Zero::zero::<V>();
@ -133,21 +137,22 @@ macro_rules! column_impl(
macro_rules! mul_impl(
($t: ident, $dim: expr) => (
impl<N: Clone + Ring> Mul<$t<N>, $t<N>> for $t<N> {
#[inline]
fn mul(&self, other: &$t<N>) -> $t<N> {
let mut res: $t<N> = Zero::zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
let mut acc = Zero::zero::<N>();
for k in range(0u, $dim) {
acc = acc + self.at((i, k)) * other.at((k, j));
}
res.set((i, j), acc);
}
}
res
}
}
@ -157,16 +162,17 @@ macro_rules! mul_impl(
macro_rules! rmul_impl(
($t: ident, $v: ident, $dim: expr) => (
impl<N: Clone + Ring> RMul<$v<N>> for $t<N> {
#[inline]
fn rmul(&self, other: &$v<N>) -> $v<N> {
let mut res : $v<N> = Zero::zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
let val = res.at(i) + other.at(j) * self.at((i, j));
res.set(i, val)
}
}
res
}
}
@ -176,16 +182,17 @@ macro_rules! rmul_impl(
macro_rules! lmul_impl(
($t: ident, $v: ident, $dim: expr) => (
impl<N: Clone + Ring> LMul<$v<N>> for $t<N> {
#[inline]
fn lmul(&self, other: &$v<N>) -> $v<N> {
let mut res : $v<N> = Zero::zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
let val = res.at(i) + other.at(j) * self.at((j, i));
res.set(i, val)
}
}
res
}
}
@ -200,7 +207,7 @@ macro_rules! transform_impl(
fn transform_vec(&self, v: &$v<N>) -> $v<N> {
self.rmul(v)
}
#[inline]
fn inv_transform(&self, v: &$v<N>) -> $v<N> {
match self.inverse() {
@ -219,7 +226,7 @@ macro_rules! inv_impl(
#[inline]
fn inverse(&self) -> Option<$t<N>> {
let mut res : $t<N> = self.clone();
if res.inplace_inverse() {
Some(res)
}
@ -227,11 +234,11 @@ macro_rules! inv_impl(
None
}
}
fn inplace_inverse(&mut self) -> bool {
let mut res: $t<N> = One::one();
let _0N: N = Zero::zero();
// inversion using Gauss-Jordan elimination
for k in range(0u, $dim) {
// search a non-zero value on the k-th column
@ -288,7 +295,7 @@ macro_rules! inv_impl(
}
}
}
*self = res;
true
@ -303,12 +310,13 @@ macro_rules! transpose_impl(
#[inline]
fn transposed(&self) -> $t<N> {
let mut res = self.clone();
res.transpose();
res
}
#[inline]
fn transpose(&mut self) {
for i in range(1u, $dim) {
for j in range(0u, i) {
@ -327,20 +335,20 @@ macro_rules! approx_eq_impl(
fn approx_epsilon() -> N {
ApproxEq::approx_epsilon::<N, N>()
}
#[inline]
fn approx_eq(&self, other: &$t<N>) -> bool {
let mut zip = self.iter().zip(other.iter());
do zip.all |(a, b)| {
a.approx_eq(b)
}
}
#[inline]
fn approx_eq_eps(&self, other: &$t<N>, epsilon: &N) -> bool {
let mut zip = self.iter().zip(other.iter());
do zip.all |(a, b)| {
a.approx_eq_eps(b, epsilon)
}
@ -352,6 +360,7 @@ macro_rules! approx_eq_impl(
macro_rules! to_homogeneous_impl(
($t: ident, $t2: ident, $dim: expr, $dim2: expr) => (
impl<N: One + Zero + Clone> ToHomogeneous<$t2<N>> for $t<N> {
#[inline]
fn to_homogeneous(&self) -> $t2<N> {
let mut res: $t2<N> = One::one();
@ -370,6 +379,7 @@ macro_rules! to_homogeneous_impl(
macro_rules! from_homogeneous_impl(
($t: ident, $t2: ident, $dim: expr, $dim2: expr) => (
impl<N: One + Zero + Clone> FromHomogeneous<$t2<N>> for $t<N> {
#[inline]
fn from(m: &$t2<N>) -> $t<N> {
let mut res: $t<N> = One::one();

View File

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

View File

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

View File

@ -147,6 +147,7 @@ macro_rules! new_repeat_impl(
macro_rules! iterable_impl(
($t: ident, $dim: expr) => (
impl<N> Iterable<N> for $t<N> {
#[inline]
fn iter<'l>(&'l self) -> VecIterator<'l, N> {
unsafe {
cast::transmute::<&'l $t<N>, &'l [N, ..$dim]>(self).iter()
@ -159,6 +160,7 @@ macro_rules! iterable_impl(
macro_rules! iterable_mut_impl(
($t: ident, $dim: expr) => (
impl<N> IterableMut<N> for $t<N> {
#[inline]
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
unsafe {
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(
($t: ident, $dim: expr) => (
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for $t<N> {
#[inline]
pub fn canonical_basis(f: &fn($t<N>)) {
for i in range(0u, $dim) {
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>)) {
// compute the basis of the orthogonal subspace using Gram-Schmidt
// orthogonalization algorithm
@ -451,6 +455,7 @@ macro_rules! one_impl(
macro_rules! from_iterator_impl(
($t: ident, $param0: ident $(, $paramN: ident)*) => (
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for $t<N> {
#[inline]
fn from_iterator($param0: &mut Iter) -> $t<N> {
$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> {
#[inline(always)]
pub fn sample(f: &fn(&'static Vec2<f64>)) {
for sample in SAMPLES_2_F64.iter() {
f(sample)
@ -151,6 +152,7 @@ impl UniformSphereSample for Vec2<f64> {
}
impl UniformSphereSample for Vec3<f64> {
#[inline(always)]
pub fn sample(f: &fn(&'static Vec3<f64>)) {
for sample in SAMPLES_3_F64.iter() {
f(sample)