Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Slightly faster Str.encode
  • Loading branch information
lizmat committed Oct 30, 2015
1 parent 4e45f0e commit 2e19ebe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/Str.pm
Expand Up @@ -1126,11 +1126,12 @@ my class Str does Stringy { # declared in BOOTSTRAP
}.new(self));
}

my %enc_type = utf8 => utf8, utf16 => utf16, utf32 => utf32;
my $enc_type := nqp::hash('utf8',utf8,'utf16',utf16,'utf32',utf32);
method encode(Str:D $encoding = 'utf8') {
my $enc := Rakudo::Internals.NORMALIZE_ENCODING($encoding);
my $enc_type := %enc_type.EXISTS-KEY($enc) ?? %enc_type{$enc} !! blob8;
nqp::encode(nqp::unbox_s(self), nqp::unbox_s($enc), nqp::decont($enc_type.new))
my str $enc = Rakudo::Internals.NORMALIZE_ENCODING($encoding);
my $type :=
nqp::existskey($enc_type,$enc) ?? nqp::atkey($enc_type,$enc) !! blob8;
nqp::encode(nqp::unbox_s(self), $enc, nqp::decont($type.new))
}

#?if moar
Expand Down

0 comments on commit 2e19ebe

Please sign in to comment.