Skip to content

Commit

Permalink
Streamline BUILDALL for 8% faster object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Feb 6, 2016
1 parent 891d456 commit 7e25273
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions src/core/Mu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Please refactor this code using the new Iterator / Seq interface.
}

method BUILDALL(@autovivs, %attrinit) {
my $init := nqp::getattr(%attrinit,Map,'$!storage');
# Get the build plan. Note that we do this "low level" to
# avoid the NQP type getting mapped to a Rakudo one, which
# would get expensive.
Expand All @@ -127,26 +128,22 @@ Please refactor this code using the new Iterator / Seq interface.
nqp::atpos($task, 1)(self, |%attrinit);
}
elsif nqp::iseq_i($code, 1) {
# See if we have a value to initialize this attr
# with.
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
# See if we have a value to initialize this attr with.
nqp::getattr(self,nqp::atpos($task,1),nqp::atpos($task,3))
= %attrinit.AT-KEY($key_name)
if %attrinit.EXISTS-KEY($key_name);
= %attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2)))
if nqp::existskey($init,nqp::atpos($task,2));
}
elsif nqp::iseq_i($code, 2) {
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
%attrinit.EXISTS-KEY($key_name)
nqp::existskey($init,nqp::atpos($task,2))
?? (nqp::getattr(self,nqp::atpos($task,1),nqp::atpos($task,3))
= %attrinit.AT-KEY($key_name))
= %attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2))))
!! nqp::bindattr(self,nqp::atpos($task,1),nqp::atpos($task,3),
nqp::list);
}
elsif nqp::iseq_i($code, 3) {
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
%attrinit.EXISTS-KEY($key_name)
nqp::existskey($init,nqp::atpos($task,2))
?? (nqp::getattr(self,nqp::atpos($task,1),nqp::atpos($task,3))
= %attrinit.AT-KEY($key_name))
= %attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2))))
!! nqp::bindattr(self,nqp::atpos($task,1),nqp::atpos($task,3),
nqp::hash);
}
Expand All @@ -157,22 +154,19 @@ Please refactor this code using the new Iterator / Seq interface.
}
}
elsif nqp::iseq_i($code, 5) {
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
nqp::bindattr_i(self,nqp::atpos($task,1),nqp::atpos($task,3),
nqp::decont(%attrinit.AT-KEY($key_name)))
if %attrinit.EXISTS-KEY($key_name);
nqp::decont(%attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2)))))
if nqp::existskey($init,nqp::atpos($task,2));
}
elsif nqp::iseq_i($code, 6) {
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
nqp::bindattr_n(self,nqp::atpos($task,1),nqp::atpos($task,3),
nqp::decont(%attrinit.AT-KEY($key_name)))
if %attrinit.EXISTS-KEY($key_name);
nqp::decont(%attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2)))))
if nqp::existskey($init,nqp::atpos($task,2));
}
elsif nqp::iseq_i($code, 7) {
my $key_name := nqp::p6box_s(nqp::atpos($task, 2));
nqp::bindattr_s(self,nqp::atpos($task,1),nqp::atpos($task,3),
nqp::decont(%attrinit.AT-KEY($key_name)))
if %attrinit.EXISTS-KEY($key_name);
nqp::decont(%attrinit.AT-KEY(nqp::p6box_s(nqp::atpos($task,2)))))
if nqp::existskey($init,nqp::atpos($task,2));
}
elsif nqp::iseq_i($code, 8) {
my int $cur_value = nqp::getattr_i(self, nqp::atpos($task, 1), nqp::atpos($task, 2));
Expand All @@ -182,10 +176,9 @@ Please refactor this code using the new Iterator / Seq interface.
}
elsif nqp::iseq_i($code, 9) {
my num $cur_value = nqp::getattr_n(self, nqp::atpos($task, 1), nqp::atpos($task, 2));
if nqp::iseq_n($cur_value, 0e0) {
nqp::bindattr_n(self, nqp::atpos($task, 1), nqp::atpos($task, 2),
nqp::atpos($task, 3)(self, $cur_value));
}
nqp::bindattr_n(self,nqp::atpos($task,1),nqp::atpos($task,2),
nqp::atpos($task,3)(self, $cur_value))
if nqp::iseq_n($cur_value, 0e0);
}
elsif nqp::iseq_i($code, 10) {
my str $cur_value = nqp::getattr_s(self, nqp::atpos($task, 1), nqp::atpos($task, 2));
Expand All @@ -194,19 +187,15 @@ Please refactor this code using the new Iterator / Seq interface.
if nqp::isnull_s($cur_value);
}
elsif nqp::iseq_i($code, 11) {
my $attr_name = nqp::p6box_s(nqp::atpos($task, 2));
unless nqp::attrinited(self, nqp::atpos($task, 1), $attr_name) {
X::Attribute::Required.new(name => $attr_name).throw;
}
my str $attr_name = nqp::atpos($task, 2);
X::Attribute::Required.new(name => $attr_name).throw
unless nqp::attrinited(self,nqp::atpos($task,1),$attr_name);
}
elsif nqp::iseq_i($code, 12) {
nqp::bindattr(self, nqp::atpos($task, 1), nqp::atpos($task, 2),
nqp::atpos($task, 3)());
}
elsif nqp::iseq_i($code, 13) {
# no-op in BUILDALL
}
else {
elsif nqp::isne_i($code, 13) { # no-op in BUILDALL
die "Invalid BUILDALLPLAN";
}
}
Expand Down

0 comments on commit 7e25273

Please sign in to comment.