Skip to content

Commit

Permalink
PROP/PVALCODE internal subs to Rakudo::Internals
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Nov 10, 2015
1 parent 6f8030b commit d2b4941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
19 changes: 19 additions & 0 deletions src/core/Rakudo/Internals.pm
Expand Up @@ -299,6 +299,25 @@ my class Rakudo::Internals {
nqp::join(nqp::unbox_s(final),
nqp::split(nqp::unbox_s(original),nqp::unbox_s(string)))
}

#?if moar
my $propcode := nqp::hash;
method PROPCODE(\propname) {
my str $key = nqp::unbox_s(propname);
nqp::bindkey($propcode,$key,nqp::unipropcode($key))
unless nqp::existskey($propcode,$key);
nqp::atkey($propcode,$key)
}
my $pvalcode := nqp::hash;
method PVALCODE(\prop,\pvalname) {
my str $pvalname = nqp::unbox_s(pvalname);
my str $key = nqp::concat(nqp::tostr_I(prop),$pvalname);
nqp::bindkey($pvalcode,$key,
nqp::unipvalcode(nqp::unbox_i(prop),$pvalname))
unless nqp::existskey($pvalcode,$key);
nqp::atkey($pvalcode,$key)
}
#?endif
}

# vim: ft=perl6 expandtab sw=4
21 changes: 6 additions & 15 deletions src/core/Str.pm
Expand Up @@ -2160,19 +2160,10 @@ multi sub unimatch(|) { die 'unimatch NYI on jvm backend' }
#?endif

#?if moar
sub PROPCODE($propname) {
state %propcode;
%propcode{$propname} //= nqp::unipropcode($propname);
}
sub PVALCODE($prop,$pvalname) {
state %pvalcode;
%pvalcode{$prop ~ $pvalname} //= nqp::unipvalcode($prop, $pvalname);
}

proto sub uniprop(|) {*}
multi sub uniprop(Str:D $str, |c) { $str ?? uniprop($str.ord, |c) !! Nil }
multi sub uniprop(Int:D $code, Stringy:D $propname = "GeneralCategory") {
my $prop := PROPCODE($propname);
my $prop := Rakudo::Internals.PROPCODE($propname);
state %prefs; # could prepopulate this with various prefs
given %prefs{$propname} // '' {
when 'S' { nqp::getuniprop_str($code,$prop) }
Expand All @@ -2191,23 +2182,23 @@ proto sub uniprop-int(|) {*}
multi sub uniprop-int(Str:D $str, Stringy:D $propname) {
$str ?? uniprop-int($str.ord, $propname) !! Str }
multi sub uniprop-int(Int:D $code, Stringy:D $propname) {
nqp::getuniprop_int($code,PROPCODE($propname));
nqp::getuniprop_int($code,Rakudo::Internals.PROPCODE($propname));
}

proto sub uniprop-bool(|) {*}
multi sub uniprop-bool(Str:D $str, Stringy:D $propname) {
$str ?? uniprop-bool($str.ord, $propname) !! Str
}
multi sub uniprop-bool(Int:D $code, Stringy:D $propname) {
so nqp::getuniprop_bool($code,PROPCODE($propname));
so nqp::getuniprop_bool($code,Rakudo::Internals.PROPCODE($propname));
}

proto sub uniprop-str(|) {*}
multi sub uniprop-str(Str:D $str, Stringy:D $propname) {
$str ?? uniprop-str($str.ord, $propname) !! Str
}
multi sub uniprop-str(Int:D $code, Stringy:D $propname) {
nqp::getuniprop_str($code,PROPCODE($propname));
nqp::getuniprop_str($code,Rakudo::Internals.PROPCODE($propname));
}

proto sub unival(|) {*}
Expand All @@ -2226,8 +2217,8 @@ multi sub univals(Str:D $str) { $str.ords.map: { unival($_) } }
proto sub unimatch(|) {*}
multi sub unimatch(Str:D $str, |c) { $str ?? unimatch($str.ord, |c) !! Nil }
multi sub unimatch(Int:D $code, Stringy:D $pvalname, Stringy:D $propname = $pvalname) {
my $prop := PROPCODE($propname);
so nqp::matchuniprop($code,$prop,PVALCODE($prop,$pvalname));
my $prop := Rakudo::Internals.PROPCODE($propname);
so nqp::matchuniprop($code,$prop,Rakudo::Internals.PVALCODE($prop,$pvalname));
}
#?endif

Expand Down

0 comments on commit d2b4941

Please sign in to comment.