Skip to content

Commit

Permalink
Make FatRat handling use positionals
Browse files Browse the repository at this point in the history
No need to use a named parameter, just pass on the type you want to
have the object created in.  Saves 1 scalar allocation per call
(which means 17 instead of 18 garbage collections in $a.Rat for ^50000)
  • Loading branch information
lizmat committed Apr 14, 2020
1 parent 2d1ba43 commit 43c7e96
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/core.c/Num.pm6
Expand Up @@ -43,8 +43,7 @@ my class Num does Real { # declared in BOOTSTRAP
!! nqp::concat($res,'e0')
}

method Rat(Num:D: Real $Epsilon = 1.0e-6, :$fat) {
my \RAT = $fat ?? FatRat !! Rat;
method Rat(Num:D: Real:D \epsilon = 1.0e-6, \RAT = Rat) {
my num $num = self;

return RAT.new(
Expand Down Expand Up @@ -73,7 +72,7 @@ my class Num does Real { # declared in BOOTSTRAP
my Int $orig_d := 0;

my num $modf_arg;
my num $epsilon = $Epsilon.Num;
my num $epsilon = epsilon.Num;

nqp::while(
nqp::isne_n($r,0e0)
Expand Down Expand Up @@ -104,7 +103,7 @@ my class Num does Real { # declared in BOOTSTRAP
}
}
method FatRat(Num:D: Real $epsilon = 1.0e-6) {
self.Rat($epsilon, :fat);
self.Rat($epsilon, FatRat);
}

multi method atan2(Num:D: Num:D $x = 1e0) {
Expand Down

0 comments on commit 43c7e96

Please sign in to comment.