Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix "abc".match(/a<(bc)>/, :as(Str)): abc -> bc
Spotted by nicq20++ .  Also removed support for as(Range) and as(Pair)
as there is no real performance win to be gotten there (at least for
now). This also removes the rather new Cursor.RANGE and Cursor.FROMTO
methods.
  • Loading branch information
lizmat committed Oct 26, 2016
1 parent 4943ef3 commit ae85bac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
45 changes: 4 additions & 41 deletions src/core/Cursor.pm
Expand Up @@ -12,49 +12,12 @@ my class Cursor does NQPCursorRole {
)
}

method FROMTO() {
nqp::if(
nqp::isgt_i(
nqp::getattr_i(self,Cursor,'$!pos'),
nqp::getattr_i(self,Cursor,'$!from')
),
Pair.new(
nqp::getattr_i(self,Cursor,'$!from'),
nqp::getattr_i(self,Cursor,'$!pos'),
),
Nil
)
}

method RANGE() {
nqp::if(
nqp::isgt_i(
nqp::getattr_i(self,Cursor,'$!pos'),
nqp::getattr_i(self,Cursor,'$!from')
),
Range.new(
nqp::getattr_i(self,Cursor,'$!from'),
nqp::sub_i(nqp::getattr_i(self,Cursor,'$!pos'),1)
),
Nil
)
}

method STR() {
nqp::if(
nqp::isgt_i(
nqp::getattr_i(self,Cursor,'$!pos'),
nqp::getattr_i(self,Cursor,'$!from')
),
nqp::substr(
nqp::findmethod(self,'orig')(self),
nqp::getattr_i(self,Cursor,'$!from'),
nqp::sub_i(
nqp::getattr_i(self,Cursor,'$!pos'),
nqp::getattr_i(self,Cursor,'$!from')
)
),
Nil
nqp::istype((my $match := nqp::getattr(self,Cursor,'$!match')),Match)
&& nqp::isconcrete($match),
$match.Str,
self!MATCH.Str
)
}

Expand Down
12 changes: 2 additions & 10 deletions src/core/Str.pm
Expand Up @@ -418,8 +418,6 @@ my class Str does Stringy { # declared in BOOTSTRAP

my \POST-MATCH := Cursor.^can("MATCH" ).AT-POS(0); # Match object
my \POST-STR := Cursor.^can("STR" ).AT-POS(0); # Str object
my \POST-RANGE := Cursor.^can("RANGE" ).AT-POS(0); # Range object
my \POST-FROMTO := Cursor.^can("FROMTO").AT-POS(0); # Pair object

# iterate with post-processing
class POST-ITERATOR does Iterator {
Expand Down Expand Up @@ -591,10 +589,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::if($ov, CURSOR-OVERLAP, CURSOR-GLOBAL))),

fetch-short-long($opts, "as", "as", my $as),
(my \post := nqp::if(
nqp::istype($as,Str), POST-STR, nqp::if(
nqp::istype($as,Range), POST-RANGE, nqp::if(
nqp::istype($as,Pair), POST-FROMTO, POST-MATCH)))),
(my \post := nqp::if(nqp::istype($as,Str), POST-STR, POST-MATCH)),

fetch-short-long($opts, "g", "global", my $g),
nqp::if(
Expand Down Expand Up @@ -646,10 +641,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
method !match-as-one(\slash, \cursor, \as) {
nqp::decont(slash = nqp::if(
nqp::isge_i(nqp::getattr_i(cursor,Cursor,'$!pos'),0),
nqp::if(nqp::istype(as,Str), POST-STR,
nqp::if(nqp::istype(as,Range), POST-RANGE,
nqp::if(nqp::istype(as,Pair), POST-FROMTO,
POST-MATCH)))(cursor),
nqp::if(nqp::istype(as,Str), POST-STR, POST-MATCH)(cursor),
Nil
))
}
Expand Down

0 comments on commit ae85bac

Please sign in to comment.