Skip to content

Commit

Permalink
Improve take[-rw], proceed, succeed.
Browse files Browse the repository at this point in the history
By making them multis, the common cases can avoid a Parcel allocation
along with the underlying list construction, as well as a call. This
takes around 5% off a "read a million lines" benchmark, and probably
is more significant in things that hot-path on gather. The succeed
improvement should help all given/when usages.
  • Loading branch information
jnthn committed Sep 6, 2014
1 parent 4a74294 commit bdf153c
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions src/core/control.pm
Expand Up @@ -37,18 +37,35 @@ my &return := -> | {
$parcel
};

my &take-rw := -> | {
my $parcel :=
&RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
proto take-rw(|) { * }
multi take-rw() {
THROW(Nil, nqp::const::CONTROL_TAKE);
Nil
}
multi take-rw(\x) {
THROW(x, nqp::const::CONTROL_TAKE);
x
}
multi take-rw(|) {
my $parcel := &RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
THROW($parcel, nqp::const::CONTROL_TAKE);
$parcel
};
my &take := -> | {
my $parcel :=
&RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
}

proto take(|) { * }
multi take() {
THROW(Nil, nqp::const::CONTROL_TAKE);
Nil
}
multi take(\x) {
THROW(nqp::p6recont_ro(x), nqp::const::CONTROL_TAKE);
x
}
multi take(|) {
my $parcel := &RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
THROW(nqp::p6recont_ro($parcel), nqp::const::CONTROL_TAKE);
$parcel
};
}

my &last := -> | {
my Mu $args := nqp::p6argvmarray();
Expand Down Expand Up @@ -83,14 +100,19 @@ my &redo := -> | {
}
};

my &succeed := -> | {
my $parcel :=
&RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
THROW(nqp::decont($parcel),
nqp::const::CONTROL_SUCCEED)
};
proto succeed(|) { * }
multi succeed() {
THROW(Nil, nqp::const::CONTROL_SUCCEED)
}
multi succeed(\x) {
THROW(nqp::decont(x), nqp::const::CONTROL_SUCCEED)
}
multi succeed(|) {
my $parcel := &RETURN-PARCEL(nqp::p6parcel(nqp::p6argvmarray(), Nil));
THROW(nqp::decont($parcel), nqp::const::CONTROL_SUCCEED)
}

my &proceed := -> {
sub proceed() {
THROW(Nil, nqp::const::CONTROL_PROCEED)
}

Expand Down

0 comments on commit bdf153c

Please sign in to comment.