Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't use a !=:= b, but !(a =:= b)
Because it's at least 25x faster.  Either this, or we may want to
prime the grammar for !=:= (because they are used a lot in iterators,
and iterators imply hot paths, generally).  Not directly noticeable
speedup in spectest, but some iterator rich apps may notice improved
performance.
  • Loading branch information
lizmat committed Nov 10, 2015
1 parent 2940709 commit 4422d81
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -98,7 +98,7 @@ augment class Any {
nqp::p6setfirstflag(&!block) if &!block.phasers('FIRST');
}

if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
# $result will be returned at the end
}
elsif ($value := $!source.pull-one()) =:= IterationEnd {
Expand Down Expand Up @@ -230,7 +230,7 @@ augment class Any {
nqp::p6setfirstflag(&!block) if &!block.phasers('FIRST');
}

if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
# $result will be returned at the end
}
elsif $!source.push-exactly($!value-buffer, $!count) =:= IterationEnd
Expand Down
7 changes: 3 additions & 4 deletions src/core/Array.pm
Expand Up @@ -647,9 +647,8 @@ my class Array { # declared in BOOTSTRAP

my $todo = nqp::getattr(self, List, '$!todo');
my $lazy;
if $todo.DEFINITE {
$lazy = $todo.reify-until-lazy() !=:= IterationEnd;
}
$lazy = !($todo.reify-until-lazy() =:= IterationEnd)
if $todo.DEFINITE;

my int $o = nqp::istype($offset,Callable)
?? $offset(self.elems)
Expand All @@ -675,7 +674,7 @@ my class Array { # declared in BOOTSTRAP

# need to enforce type checking
my $expected := self.of;
if self.of !=:= Mu {
unless self.of =:= Mu {
my int $i = 0;
my int $n = nqp::elems(splice-buffer);
while $i < $n {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Iterator.pm
Expand Up @@ -82,7 +82,7 @@ my role Iterator {
# if "foo".IO.lines { , where we're only interested whether there is *any*
# line in the file, rather than the content of the line.
method bool-only() {
self.pull-one() !=:= IterationEnd;
!(self.pull-one() =:= IterationEnd)
}

# Consumes all of the values in the iterator for their side-effects only.
Expand Down
6 changes: 3 additions & 3 deletions src/core/List.pm
Expand Up @@ -1045,7 +1045,7 @@ multi sub infix:<X>(+lol) {
my @i = @l.map: *.iterator;
while $i >= 0 {
my \e = @i[$i].pull-one();
if e !=:= IterationEnd {
if !(e =:= IterationEnd) {
nqp::bindpos($v, $i, e);
if $i >= $n { take nqp::clone($v) }
else {
Expand Down Expand Up @@ -1108,7 +1108,7 @@ multi sub infix:<X>(+lol) {
gather {
while $i == 0 {
my \e = source.pull-one;
if e !=:= IterationEnd {
if !(e =:= IterationEnd) {
nqp::bindpos($v, $i, e);

if $i >= $n { take nqp::clone($v) }
Expand Down Expand Up @@ -1180,7 +1180,7 @@ sub roundrobin(**@lol) {
my @values;
for @iters -> $i {
my \v = $i.pull-one;
if v !=:= IterationEnd {
unless v =:= IterationEnd {
@values.push: v;
@new-iters.push: $i;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Map.pm
Expand Up @@ -191,7 +191,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
elsif nqp::istype($x, Map) and !nqp::iscont($x) {
for $x.list { self.STORE_AT_KEY(.key, .value) }
}
elsif (my Mu $y := iter.pull-one) !=:= IterationEnd {
elsif !((my Mu $y := iter.pull-one) =:= IterationEnd) {
self.STORE_AT_KEY($x, $y)
}
else {
Expand Down
10 changes: 5 additions & 5 deletions src/core/Seq.pm
Expand Up @@ -151,7 +151,7 @@ my class Seq is Cool does Iterable does PositionalBindFailover {
method pull-one() {
my int $redo = 1;
my $result;
if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
$result
}
else {
Expand Down Expand Up @@ -198,7 +198,7 @@ my class Seq is Cool does Iterable does PositionalBindFailover {
method pull-one() {
my int $redo = 1;
my $result;
if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
$result
}
else {
Expand Down Expand Up @@ -253,7 +253,7 @@ my class Seq is Cool does Iterable does PositionalBindFailover {
method pull-one() {
my int $redo = 1;
my $result;
if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
$result
}
else {
Expand Down Expand Up @@ -348,7 +348,7 @@ sub GATHER(&block) {
}

method pull-one() {
if $!slipping && (my \result = self.slip-one()) !=:= IterationEnd {
if $!slipping && !((my \result = self.slip-one()) =:= IterationEnd) {
result
}
else {
Expand All @@ -366,7 +366,7 @@ sub GATHER(&block) {
if ($n > 0) {
$!wanted = $n;
$!push-target := $target;
if $!slipping && self!slip-wanted() !=:= IterationEnd {
if $!slipping && !(self!slip-wanted() =:= IterationEnd) {
$!push-target := Mu;
$n
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Signature.pm
Expand Up @@ -63,7 +63,7 @@ my class Signature { # declared in BOOTSTRAP
my $this;

if $other.slurpy {
return False if any($here.keys) ~~ { .type !=:= Mu };
return False if any($here.keys) ~~ { !(.type =:= Mu) };
return $hasslurpy;
}
if $this=$here.keys.grep( -> $t { $other ~~ $t }) {
Expand Down Expand Up @@ -109,7 +109,7 @@ my class Signature { # declared in BOOTSTRAP
!! ', '
}
}
if !nqp::isnull($!returns) && $!returns !=:= Mu {
if !nqp::isnull($!returns) && !($!returns =:= Mu) {
$text = $text ~ ' --> ' ~ $!returns.perl
}
# Closer.
Expand Down
3 changes: 2 additions & 1 deletion src/core/array_slice.pm
Expand Up @@ -288,7 +288,8 @@ multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, Mu \val ) is raw {
for $max ^.. $p -> $i {
$max = $i;
my $lv := $target.pull-one;
%keep{$i} := $lv if %keep{$i}:exists and $lv !=:= IterationEnd;
%keep{$i} := $lv
if %keep{$i}:exists and !($lv =:= IterationEnd);
}
$lv := %keep{$p};
$lv = rviter.pull-one;
Expand Down
14 changes: 7 additions & 7 deletions src/core/metaops.pm
Expand Up @@ -50,7 +50,7 @@ sub METAOP_CROSS(\op, &reduce) {
if $i >= $n { take lol.elems == 2 ?? $rop(|@v) !! $rop(@v); }
else { $i = $i + 1; @j.push($j); $j = 0; }
}
elsif (my \value = @loi[$i].pull-one) !=:= IterationEnd {
elsif !((my \value = @loi[$i].pull-one) =:= IterationEnd) {
nqp::bindpos($sublist, $j, value);
redo;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ multi sub METAOP_REDUCE_RIGHT(\op, \triangle) {
my @args.unshift: first;
GATHER({
take first;
while (my \current = source.pull-one) !=:= IterationEnd {
while !((my \current = source.pull-one) =:= IterationEnd) {
@args.unshift: current;
if @args.elems == $count {
my \val = op.(|@args);
Expand All @@ -223,7 +223,7 @@ multi sub METAOP_REDUCE_RIGHT(\op, \triangle) {

gather {
take $result;
while (my $elem := iter.pull-one) !=:= IterationEnd {
while !((my $elem := iter.pull-one) =:= IterationEnd) {
take $result := op.($elem, $result)
}
}.lazy-if(values.is-lazy);
Expand Down Expand Up @@ -338,13 +338,13 @@ multi sub METAOP_REDUCE_CHAIN(\op, \triangle) {
my Mu $current = iter.pull-one;
gather {
take $state;
while $state && (my $next := iter.pull-one) !=:= IterationEnd {
while $state && !((my $next := iter.pull-one) =:= IterationEnd) {
$state = op.($current, $next);
take $state;
$current := $next;
}
unless $state {
while (my \v = iter.pull-one) !=:= IterationEnd {
while !((my \v = iter.pull-one) =:= IterationEnd) {
take False;
}
}
Expand All @@ -361,7 +361,7 @@ multi sub METAOP_REDUCE_CHAIN(\op) {
my $current := iter.pull-one;
return True if $current =:= IterationEnd;

while (my $next := iter.pull-one) !=:= IterationEnd {
while !((my $next := iter.pull-one) =:= IterationEnd) {
$state := op.($current, $next);
return $state unless $state;
$current := $next;
Expand Down Expand Up @@ -555,7 +555,7 @@ multi sub deepmap(\op, \obj) {
my int $redo = 1;
my $value;
my $result;
if $!slipping && ($result := self.slip-one()) !=:= IterationEnd {
if $!slipping && !(($result := self.slip-one()) =:= IterationEnd) {
$result
}
elsif ($value := $!source.pull-one()) =:= IterationEnd {
Expand Down
2 changes: 1 addition & 1 deletion src/core/operators.pm
Expand Up @@ -167,7 +167,7 @@ sub SEQUENCE(\left, Mu \right, :$exclude_end) {
my $code;
my $stop;
my $looped;
while (my \value := lefti.pull-one) !=:= IterationEnd {
while !((my \value := lefti.pull-one) =:= IterationEnd) {
$looped = True;
if nqp::istype(value,Code) { $code = value; last }
if $end_code_arity != 0 {
Expand Down

0 comments on commit 4422d81

Please sign in to comment.