Skip to content

Commit

Permalink
Improve object creation performance in a few hot-path places (e.g. it…
Browse files Browse the repository at this point in the history
…erators).
  • Loading branch information
jnthn committed Sep 16, 2011
1 parent c8ebb4b commit 0a93f6e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/Complex.pm
Expand Up @@ -5,7 +5,7 @@ my class Complex is Numeric {

proto method new(|$) { * }
multi method new(Real \$re, Real \$im) {
my $new = self.CREATE;
my $new = nqp::create(self);
$new.BUILD($re.Num, $im.Num);
$new;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Enum.pm
Expand Up @@ -2,7 +2,7 @@ my class Enum {
has $.key;
has $.value;

method new(:$key, Mu :$value) { self.CREATE.BUILD($key, $value) }
method new(:$key, Mu :$value) { nqp::create(self).BUILD($key, $value) }
method BUILD(\$key, Mu \$value) { $!key = $key; $!value = $value; self }

multi method ACCEPTS(Enum:D: Associative:D $topic) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/GatherIter.pm
Expand Up @@ -12,7 +12,7 @@ class GatherIter is Iterator {
$P1($P0)
};
pir::setattribute__0PPsP(
pir::setattribute__0PPsP(self.CREATE, GatherIter, '$!coro', $coro),
pir::setattribute__0PPsP(nqp::create(self), GatherIter, '$!coro', $coro),
GatherIter, '$!infinite', $infinite);
}

Expand All @@ -36,7 +36,7 @@ class GatherIter is Iterator {
nqp::push($rpa,
pir::setattribute__0PPsP(
pir::setattribute__0PPsP(
self.CREATE, GatherIter, '$!coro', $!coro),
nqp::create(self), GatherIter, '$!coro', $!coro),
GatherIter, '$!infinite', $!infinite))
unless $end;
$!reified := nqp::p6parcel($rpa, nqp::null());
Expand Down
4 changes: 2 additions & 2 deletions src/core/MapIter.pm
Expand Up @@ -4,7 +4,7 @@ my class MapIter is Iterator {
has $!block; # the block we're applying

method new(:$list!, :$block!) {
my $new := self.CREATE.BUILD($list, $block);
my $new := nqp::create(self).BUILD($list, $block);
$new;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ my class MapIter is Iterator {
%r = args
};
# create the next MapIter if we haven't reached the end
nqp::push($rpa, self.CREATE.BUILD($!list, $!block))
nqp::push($rpa, nqp::create(self).BUILD($!list, $!block))
if $args;
$!reified := nqp::p6parcel($rpa, nqp::null());
$!list = Any;
Expand Down
11 changes: 4 additions & 7 deletions src/core/Range.pm
Expand Up @@ -6,16 +6,13 @@ class Range is Iterable does Positional {

proto method new(|$) { * }
multi method new($min, $max, :$excludes_min, :$excludes_max) {
my $new = self.CREATE;
$new.BUILD($min, $max, $excludes_min, $excludes_max)
nqp::create(self).BUILD($min, $max, $excludes_min, $excludes_max)
}
multi method new($min, Whatever $max, :$excludes_min, :$excludes_max) {
my $new = self.CREATE;
$new.BUILD($min, $Inf, $excludes_min, $excludes_max)
nqp::create(self).BUILD($min, $Inf, $excludes_min, $excludes_max)
}
multi method new(Whatever $min, $max, :$excludes_min, :$excludes_max) {
my $new = self.CREATE;
$new.BUILD(-$Inf, $max, $excludes_min, $excludes_max)
nqp::create(self).BUILD(-$Inf, $max, $excludes_min, $excludes_max)
}
multi method new(Whatever $min, Whatever $max, :$excludes_min, :$excludes_max) {
fail "*..* is not a valid range";
Expand Down Expand Up @@ -107,7 +104,7 @@ class Range is Iterable does Positional {
if ($value cmp $!max) < $cmpstop {
nqp::push($rpa,
($value.succ cmp $!max < $cmpstop)
?? self.CREATE.BUILD($value, $!max, 0, $!excludes_max)
?? nqp::create(self).BUILD($value, $!max, 0, $!excludes_max)
!! $value);
}
nqp::p6parcel($rpa, nqp::null());
Expand Down
2 changes: 1 addition & 1 deletion src/core/Rat.pm
Expand Up @@ -4,7 +4,7 @@ my class Rat is Real {
has $.denominator;

method new(Int \$nu = 0, Int \$de = 1) {
my $new := self.CREATE;
my $new := nqp::create(self);
my $gcd = $nu gcd $de;
my $numerator = $nu div $gcd;
my $denominator = $de div $gcd;
Expand Down

0 comments on commit 0a93f6e

Please sign in to comment.