Skip to content
Permalink
Browse files

Optimize assigning metaops

If the metaop is one of the >>op=<< persuasion, then we don't need to build
a result to return, as the left hand side of the op *is* the result.  This
makes >>+=<< about 8% faster.
  • Loading branch information...
lizmat committed Nov 16, 2018
1 parent c444564 commit 19f0c842765726fbd65285acfd8870a79709a378
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/core/Hyper.pm6
@@ -7,17 +7,18 @@ class Hyper {
has int8 $.assigns; # assigns to left side

method new(\op, Bool() :$dwim-left, Bool() :$dwim-right) {
my $assigns = so (op.WHY && op.WHY.Str eq 'METAOP_ASSIGN');
self.bless(
:operator(op),
:$dwim-left,
:$dwim-right,
:assigns(op.name.ends-with("=>")),
:$assigns,
)
}

# for error messages
method name() {
my str $name = $!operator.name || 'infix:<op>';
my str $name = $!operator.name || "infix:<op{'=' if $!assigns}>";
my int $start = nqp::index($name,"«");
$start = nqp::index($name,"<") if $start == -1;
my int $end = nqp::index($name,"»");

1 comment on commit 19f0c84

@b2gills

This comment has been minimized.

Copy link
Contributor

commented on 19f0c84 Nov 16, 2018

Perhaps a note about the WHY comment being used for this optimization would be a good addition to the METAOP_ASSIGN subroutine.

Please sign in to comment.
You can’t perform that action at this time.