Skip to content

Commit

Permalink
Make Rat.FatRat about 5x as fast
Browse files Browse the repository at this point in the history
Since the Rat's attributes are already normalized, there is no
reason to go through the whole normalization process again.

This also affects FatRat literals in the form 0.1234.FatRat, as
these are currently codegenned as Rat WVal's with the .FatRat
method called on them at runtime.
  • Loading branch information
lizmat committed Jan 11, 2022
1 parent d6e6afb commit 82afbbf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core.c/Rat.pm6
Expand Up @@ -4,7 +4,12 @@ my class Rat is Cool does Rational[Int, Int] {
self
}
method FatRat(Rat:D: Real $? --> FatRat:D) {
FatRat.new($!numerator, $!denominator)
nqp::p6bindattrinvres(
nqp::p6bindattrinvres(
nqp::create(FatRat),FatRat,'$!numerator',$!numerator
),
FatRat,'$!denominator',$!denominator
)
}
multi method raku(Rat:D: --> Str:D) {
if $!denominator == 1 {
Expand Down

0 comments on commit 82afbbf

Please sign in to comment.