Skip to content

Commit

Permalink
Use nqp::push(foo,bar) instead of foo[+foo] := bar
Browse files Browse the repository at this point in the history
nqp::push has a smaller bytecode size and is about 1.7x as fast.
Hopefully also helps with better inlining
  • Loading branch information
lizmat committed Feb 27, 2024
1 parent 3271329 commit 71dcfd4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/AttributeContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ role Perl6::Metamodel::AttributeContainer {
"' already has an attribute named '$name'");
}
if $!attr_rw_by_default { $meta_attr.default_to_rw() }
@!attributes[+@!attributes] := $meta_attr;
nqp::push(@!attributes, $meta_attr);
%!attribute_lookup{$name} := $meta_attr;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Perl6/Metamodel/ClassHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Perl6::Metamodel::ClassHOW
my %desc;
%desc<cond> := $condition;
%desc<calc> := $calculator;
@!fallbacks[+@!fallbacks] := %desc;
nqp::push(@!fallbacks, %desc);
}

sub has_method($target, $name) {
Expand Down Expand Up @@ -120,8 +120,8 @@ class Perl6::Metamodel::ClassHOW
my @ins_roles;
while @roles_to_compose {
my $r := @roles_to_compose.pop();
@!roles[+@!roles] := $r;
@!role_typecheck_list[+@!role_typecheck_list] := $r;
nqp::push(@!roles, $r);
nqp::push(@!role_typecheck_list, $r);
my $ins := $r.HOW.specialize($r, $target);
# If class is a result of pun then transfer hidden flag from the source role
if $!pun_source =:= $r {
Expand All @@ -140,9 +140,9 @@ class Perl6::Metamodel::ClassHOW
# Add them to the typecheck list, and pull in their
# own type check lists also.
for @ins_roles {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
for $_.HOW.role_typecheck_list($_) {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Perl6/Metamodel/ConcreteRoleHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ class Perl6::Metamodel::ConcreteRoleHOW
}

method add_collision($XXX, $colliding_name, @role_names, :$private = 0, :$multi) {
@!collisions[+@!collisions] := Collision.new(
nqp::push(@!collisions, Collision.new(
:name($colliding_name), :roles(@role_names), :$private, :$multi
);
));
}

method compose($target) {
$target := nqp::decont($target);

Perl6::Metamodel::Configuration.role_to_role_applier_type.apply($target, self.roles_to_compose($target));
for self.roles_to_compose($target) {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
for $_.HOW.role_typecheck_list($_) {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
}
}
for @!roles {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
for $_.HOW.role_typecheck_list($_) {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
}
}
self.publish_type_cache($target);
Expand All @@ -82,7 +82,7 @@ class Perl6::Metamodel::ConcreteRoleHOW
}

method add_to_role_typecheck_list($XXX, $type) {
@!role_typecheck_list[+@!role_typecheck_list] := $type;
nqp::push(@!role_typecheck_list, $type);
}

method role_typecheck_list($XXX?) { @!role_typecheck_list }
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/Concretization.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ role Perl6::Metamodel::Concretization {
my $lock := NQPLock.new;

method add_concretization($XXX, $role, $concrete) {
@!concretizations[+@!concretizations] := [$role, $concrete];
nqp::push(@!concretizations, nqp::list($role, $concrete))
}

method concretizations($target, :$local = 0, :$transitive = 1) {
Expand Down
10 changes: 5 additions & 5 deletions src/Perl6/Metamodel/EnumHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Perl6::Metamodel::EnumHOW

method add_enum_value($XXX, $value) {
%!values{nqp::unbox_s($value.key)} := $value.value;
@!enum_value_list[+@!enum_value_list] := $value;
nqp::push(@!enum_value_list, $value);
nqp::scwbdisable();
$!value_to_enum := NQPMu;
nqp::scwbenable();
Expand Down Expand Up @@ -108,8 +108,8 @@ class Perl6::Metamodel::EnumHOW
if @roles_to_compose {
my @ins_roles;
while @roles_to_compose {
my $r := @roles_to_compose.pop();
@!role_typecheck_list[+@!role_typecheck_list] := $r;
my $r := nqp::pop(@roles_to_compose);
nqp::push(@!role_typecheck_list, $r);
my $ins := $r.HOW.specialize($r, $target);
self.check-type-compat($target, $ins, [3])
if nqp::istype($ins.HOW, Perl6::Metamodel::LanguageRevision);
Expand All @@ -121,9 +121,9 @@ class Perl6::Metamodel::EnumHOW
# Add them to the typecheck list, and pull in their
# own type check lists also.
for @ins_roles {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
for $_.HOW.role_typecheck_list($_) {
@!role_typecheck_list[+@!role_typecheck_list] := $_;
nqp::push(@!role_typecheck_list, $_);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Perl6/Metamodel/MethodContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ role Perl6::Metamodel::MethodContainer {
self.invalidate_method_caches($target);
}
%!cache := {};
@!method_order[+@!method_order] := $code_obj;
@!method_names[+@!method_names] := $name;
nqp::push(@!method_order, $code_obj);
nqp::push(@!method_names, $name);
}

# Gets the method hierarchy.
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/MultiMethodContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ role Perl6::Metamodel::MultiMethodContainer {
}
my $how := MultiToIncorporate.HOW.WHAT;
my $todo := MultiToIncorporate.new( :name($name), :code(nqp::decont($code_obj)) );
@!multi_methods_to_incorporate[+@!multi_methods_to_incorporate] := $todo;
nqp::push(@!multi_methods_to_incorporate, $todo);
%!multi_candidate_names{$name} := 1;
$code_obj;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Perl6/Metamodel/MultipleInheritance.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ role Perl6::Metamodel::MultipleInheritance {
if nqp::istype(self, Perl6::Metamodel::MROBasedMethodDispatch) {
self.invalidate_method_caches($target);
}
if $hides {
@!hides[+@!hides] := $parent;
}
@!parents[+@!parents] := $parent;
nqp::push(@!hides, $parent) if $hides;
nqp::push(@!parents, $parent);
}

# Introspects the parents.
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/ParametricRoleGroupHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
}

method add_possibility($target, $possible) {
@!candidates[+@!candidates] := $possible;
nqp::push(@!candidates, $possible);
nqp::push(@!nonsignatured, nqp::decont($possible)) unless $possible.HOW.signatured($possible);
$!selector.add_dispatchee($possible.HOW.body_block($possible));
self.update_role_typecheck_list($target);
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/RoleContainer.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ role Perl6::Metamodel::RoleContainer {
has @!roles_to_compose;

method add_role($XXX, $role) {
@!roles_to_compose[+@!roles_to_compose] := nqp::decont($role)
nqp::push(@!roles_to_compose, nqp::decont($role))
}

method roles_to_compose($XXX?) { @!roles_to_compose }
Expand Down

0 comments on commit 71dcfd4

Please sign in to comment.