Skip to content

Commit

Permalink
NQPise internal ENUM_VALUES sub
Browse files Browse the repository at this point in the history
Since a Map is needed at the end, we don't need to make a HLL Hash for that
  • Loading branch information
lizmat committed Nov 29, 2019
1 parent 488f21a commit a51268a
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/core.c/Enumeration.pm6
Expand Up @@ -86,20 +86,16 @@ my role NumericStringyEnumeration {
}
}

sub ENUM_VALUES(*@args) {
sub ENUM_VALUES(*@args --> Map:D) {
my Mu $prev = -1;
my %res;
for @args {
if .^isa(Pair) {
%res{.key} = $prev = .value;
}
else {
%res{$_} = $prev.=succ;
}
}
nqp::p6bindattrinvres(
nqp::create(Map),Map,'$!storage',nqp::getattr(%res,Map,'$!storage')
)
my $res := nqp::hash;

nqp::istype($_,Pair)
?? nqp::bindkey($res, .key, nqp::decont($prev = .value))
!! nqp::bindkey($res, $_, nqp::decont($prev = $prev.succ))
for @args;

nqp::p6bindattrinvres(nqp::create(Map),Map,'$!storage',$res)
}

Metamodel::EnumHOW.set_composalizer(-> $type, $name, @enum_values {
Expand Down

0 comments on commit a51268a

Please sign in to comment.