Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
totally speed up prefix:<->(Complex), or so I hope.
This patch replaces one line of code with 10, but it should avoid any box and unbox operation.
Doing the same with operators will be rather straight-forward, but quite repetitive.
I wonder if it could be automated. I have read about tools called "compilers" that could
make such a task much easier... :-)
  • Loading branch information
moritz committed Jul 1, 2011
1 parent 71607fa commit 080e492
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/Complex.pm
Expand Up @@ -62,7 +62,18 @@ my class Complex is Numeric {
}

multi sub prefix:<->(Complex \$a) {
Complex.new(-$a.re, -$a.im);
my $new := nqp::create(Complex);
nqp::bindattr_n( $new, Complex, '$!re',
nqp::neg_n(
nqp::getattr_n(pir::perl6_decontainerize__PP($a), Complex, '$!re')
)
);
nqp::bindattr_n( $new, Complex, '$!im',
nqp::neg_n(
nqp::getattr_n(pir::perl6_decontainerize__PP($a), Complex, '$!im')
)
);
$new;
}

multi sub infix:<+>(Complex \$a, Complex \$b) {
Expand Down

0 comments on commit 080e492

Please sign in to comment.