Skip to content

Commit

Permalink
Make Pair.raku about 15% faster
Browse files Browse the repository at this point in the history
- formerly known as Pair.perl
- adds a Str.is-identifier method that returns True matches identifier syntax
  - since this appears to be generally useful, it seems like a good addition
  • Loading branch information
lizmat committed Jan 5, 2020
1 parent 585227e commit 0d96bed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core.c/Pair.pm6
Expand Up @@ -105,10 +105,10 @@ key of the Pair should be a valid method name, not '$method'."
})
}

multi method raku(Pair:D: :$arglist) {
multi method raku(Pair:D: Bool:D :$arglist = False) {
self.rakuseen('Pair', -> :$arglist {
nqp::istype($!key, Str) && nqp::isconcrete($!key)
?? !$arglist && $!key ~~ /^ [<alpha>\w*] +% <[\-']> $/
?? nqp::not_i($arglist) && $!key.is-identifier
?? nqp::istype($!value,Bool) && nqp::isconcrete($!value)
?? ':' ~ '!' x !$!value ~ $!key
!! ':' ~ $!key ~ '(' ~ $!value.raku ~ ')'
Expand Down
11 changes: 11 additions & 0 deletions src/core.c/Str.pm6
Expand Up @@ -37,6 +37,17 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::bindattr_s(self, Str, '$!value', nqp::unbox_s($value))
}

method is-identifier(Str:D: ) {
for self.split: ("-","'") -> str $part {
return False
unless nqp::chars($part) && nqp::findnotcclass(
nqp::const::CCLASS_ALPHABETIC,
$part,0,nqp::chars($part)
) == nqp::chars($part)
}
True
}

multi method Bool(Str:D: --> Bool:D) {
nqp::hllbool(nqp::chars($!value));
}
Expand Down

0 comments on commit 0d96bed

Please sign in to comment.