Skip to content
Permalink
Browse files

Extract Str.words(:autoderef) and streamline it

The runtime post-processing of quoted words used a special candidate
of Str.words.  By giving the method its own name, it is no longer part
of the MMD of Str.words *and* we can remove a named parameter to the
call.  The inside of the method could also be streamlined a bit so that
we have a lot less boxing going on.
  • Loading branch information...
lizmat committed Sep 5, 2018
1 parent 1905838 commit 92951168bdac4196f82a1d9ee2eea45df6d874ec
Showing with 16 additions and 8 deletions.
  1. +8 −4 src/Perl6/Actions.nqp
  2. +8 −4 src/core/Str.pm6
@@ -10482,7 +10482,12 @@ class Perl6::QActions is HLL::Actions does STDActions {
}
}
else {
$past := QAST::Op.new( :op('callmethod'), :name('words'), :node($/), $past, QAST::IVal.new( :value(1), :named('autoderef') ) );
$past := QAST::Op.new(
:op('callmethod'),
:name('words-autoderef'),
:node($/),
$past
);
}
$past
}
@@ -10510,14 +10515,13 @@ class Perl6::QActions is HLL::Actions does STDActions {
:name('Slip'),
QAST::Op.new(
:op('callmethod'),
:name('words'),
:name('words-autoderef'),
:node($/),
QAST::Op.new(
:op('callmethod'),
:name('Stringy'),
$node
),
QAST::IVal.new( :value(1), :named('autoderef') )
)
)
)
);
@@ -2139,10 +2139,6 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

proto method words(|) {*}
multi method words(Str:D: :$autoderef!) { # in Actions.postprocess_words
my @list := self.words.List;
return @list == 1 ?? @list[0] !! @list;
}
multi method words(Str:D: $limit) {
nqp::istype($limit,Whatever) || $limit == Inf
?? self.words
@@ -2195,6 +2191,14 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
multi method words(Str:D:) { Seq.new(Words.new(self)) }

# Internal method, used in Actions.postprocess_words/postprocess_quotewords
method words-autoderef(Str:D:) {
Words.new(self).push-all(my $words := nqp::create(IterationBuffer));
nqp::elems($words) == 1
?? nqp::shift($words)
!! nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$words)
}

proto method encode(|) {*}
multi method encode(Str:D $encoding = 'utf8', :$replacement, Bool() :$translate-nl = False, :$strict) {
Encoding::Registry.find($encoding)

0 comments on commit 9295116

Please sign in to comment.
You can’t perform that action at this time.