Skip to content

Commit

Permalink
Use --/++$i instead of $i = nqp::add/sub_i($i,1)
Browse files Browse the repository at this point in the history
String related
  • Loading branch information
lizmat committed Feb 16, 2022
1 parent 6513988 commit 8077ebd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
48 changes: 24 additions & 24 deletions src/core.c/Str.pm6
Expand Up @@ -886,7 +886,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
my str $char;
my int $ord;
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$chars), # check all chars
nqp::islt_i(++$i,$chars), # check all chars
nqp::stmts(
($char = nqp::substr(self,$i,1)),
($ord = nqp::ord($char)),
Expand Down Expand Up @@ -944,20 +944,20 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
method new($string) { nqp::create(self)!SET-SELF($string) }
method pull-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::chars($!str))
nqp::islt_i(++$!pos,nqp::chars($!str))
?? nqp::box_s(nqp::substr($!str,$!pos,1),$!what) #?js: NFG
!! IterationEnd
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::chars($!str))
nqp::islt_i(++$!pos,nqp::chars($!str))
}
method push-all(\target --> IterationEnd) {
my str $str = $!str; # locals are faster
my int $pos = $!pos;
my int $chars = nqp::chars($str);
my Mu $what := $!what;
nqp::while(
nqp::islt_i(($pos = nqp::add_i($pos,1)),$chars),
nqp::islt_i(++$pos,$chars),
target.push(nqp::box_s(nqp::substr($str,$pos,1),$what)) #?js: NFG
);
$!pos = $pos;
Expand Down Expand Up @@ -995,7 +995,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
!! Rakudo::Iterator.Empty
}
method pull-one() {
($!todo = nqp::sub_i($!todo,1))
--$!todo
?? nqp::box_s(
nqp::substr( #?js: NFG
$!str,
Expand All @@ -1014,7 +1014,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
my Mu $what := $!what;

nqp::while(
($todo = nqp::sub_i($todo,1)),
--$todo,
target.push(
nqp::box_s(
nqp::substr( #?js: NFG
Expand Down Expand Up @@ -1099,7 +1099,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
IterationEnd,
nqp::stmts(
($!pos = nqp::add_i($found,1)),
($!todo = nqp::sub_i($!todo,1)),
--$!todo,
nqp::box_s($!pat,$!what)
)
)
Expand Down Expand Up @@ -1220,7 +1220,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
my $list := nqp::getattr(@names,List,'$!reified');
my int $i = -1;
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::islt_i(++$i,$elems),
nqp::if(
nqp::existskey(opts,nqp::unbox_s(nqp::atpos($list,$i))),
(store = nqp::atkey(opts,nqp::unbox_s(nqp::atpos($list,$i)))),
Expand Down Expand Up @@ -1444,7 +1444,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::stmts(
nqp::while(
nqp::isgt_i($skip,1) && iterator.skip-one,
($skip = nqp::sub_i($skip,1))
--$skip
),
nqp::if(
nqp::iseq_i($skip,1),
Expand All @@ -1467,7 +1467,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::setelems(nqp::create(IterationBuffer),$todo)),
(my int $i = -1),
nqp::until(
nqp::iseq_i(($i = nqp::add_i($i,1)),$todo)
nqp::iseq_i(++$i,$todo)
|| nqp::eqaddr(
($pulled := iterator.pull-one),IterationEnd),
nqp::bindpos($matches,$i,$pulled)
Expand Down Expand Up @@ -1541,7 +1541,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
(my int $todo = nqp::if($max == Inf, 0x7fffffff, $max)),
(my $matches := nqp::create(IterationBuffer)),
nqp::until(
nqp::islt_i(($todo = nqp::sub_i($todo,1)), 0) ||
nqp::islt_i(--$todo, 0) ||
nqp::eqaddr((my $pulled := $iterator.pull-one),IterationEnd),
nqp::push($matches,$pulled)
),
Expand Down Expand Up @@ -2194,20 +2194,20 @@ my class Str does Stringy { # declared in BOOTSTRAP

nqp::not_i(nqp::isne_i(
nqp::chars(nqp::atpos($matches,$i)),0)))
while $i = nqp::sub_i($i,1);
while --$i;
nqp::splice($matches,$empty,0,1)
unless nqp::chars(nqp::atpos($matches,0));
}
else {
nqp::splice($matches,$match-list,$i,0)
while $i = nqp::sub_i($i,1);
while --$i;
}
}
}
elsif $skip-empty {
my int $i = nqp::elems($matches);
my $match-list := nqp::list;
while nqp::isge_i($i = nqp::sub_i($i,1),0) {
while nqp::isge_i(--$i,0) {
nqp::splice($matches,$match-list,$i,1)
if nqp::iseq_i(nqp::chars(nqp::atpos($matches,$i)),0);
}
Expand Down Expand Up @@ -2431,7 +2431,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::stmts(
(my int $todo = $limit),
nqp::while(
nqp::isge_i(($todo = nqp::sub_i($todo,1)),0)
nqp::isge_i(--$todo,0)
&& nqp::isge_i($i = nqp::index($str,$need,$pos),0),
nqp::stmts(
nqp::push($positions,nqp::list_i($i,$index)),
Expand All @@ -2452,7 +2452,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
nqp::add_i($fired,nqp::isge_i(nqp::elems($positions),$seen)))
)
);
$index = nqp::add_i($index, 1);
++$index;
}

# no needle tried, assume we want chars
Expand Down Expand Up @@ -2485,15 +2485,15 @@ my class Str does Stringy { # declared in BOOTSTRAP
my int $pos;
my int $i = -1;
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
nqp::islt_i(++$i,$elems)
&& nqp::islt_i($limited,$limit),
nqp::if(
nqp::isge_i( # not hidden by other needle
nqp::atpos_i(nqp::atpos($positions,$i),0),
$pos
),
nqp::stmts(
($limited = nqp::add_i($limited,1)),
++$limited,
($pos = nqp::add_i(
nqp::atpos_i(nqp::atpos($positions,$i),0),
nqp::atpos_i($needle-chars,
Expand All @@ -2516,7 +2516,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
my int $i = -1;
my int $elems = nqp::elems($positions);
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::islt_i(++$i,$elems),
nqp::if(
nqp::isge_i( # not hidden by other needle
(my int $from = nqp::atpos_i(
Expand Down Expand Up @@ -2558,7 +2558,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
my int $i = -1;
my int $elems = nqp::elems($positions);
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::islt_i(++$i,$elems),
nqp::if(
nqp::isge_i( # not hidden by other needle
(my int $from = nqp::atpos_i(
Expand Down Expand Up @@ -2616,7 +2616,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
)),

nqp::while( # other chars in pattern
nqp::islt_i(($i = nqp::add_i($i,1)),$cases-chars),
nqp::islt_i(++$i,$cases-chars),
nqp::stmts(
(my int $case = nqp::if( # -1 =lc, 1 = uc, 0 = else
nqp::iscclass(nqp::const::CCLASS_LOWERCASE,$cases,$i),
Expand Down Expand Up @@ -2675,7 +2675,7 @@ my class Str does Stringy { # declared in BOOTSTRAP

(my int $i = -1),
nqp::while( # for all marks
nqp::islt_i(($i = nqp::add_i($i,1)),$marks-elems),
nqp::islt_i(++$i,$marks-elems),
nqp::bindpos_s($result,$i, # store the result of:
nqp::stmts(
(my $marks-nfd := nqp::strtocodes( # char + accents of mark
Expand All @@ -2701,9 +2701,9 @@ my class Str does Stringy { # declared in BOOTSTRAP
)
),

($i = nqp::sub_i($i,1)),
--$i,
nqp::while( # remaining base chars
nqp::islt_i(($i = nqp::add_i($i,1)),$base-elems),
nqp::islt_i(++$i,$base-elems),
nqp::bindpos_s($result,$i, # store the result of:
nqp::stmts(
($marks-base := nqp::strtocodes( # char+all accents of base
Expand Down
46 changes: 23 additions & 23 deletions src/core.c/allomorphs.pm6
Expand Up @@ -327,7 +327,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
my int $ch = nqp::ord($str, $pos);
my int $neg = nqp::iseq_i($ch, 45) || nqp::iseq_i($ch, 8722); # '-', '−'
if $neg || nqp::iseq_i($ch, 43) { # '-', '−', '+'
$pos = nqp::add_i($pos, 1);
++$pos;
$ch = nqp::islt_i($pos, $eos) && nqp::ord($str, $pos);
}

Expand Down Expand Up @@ -360,7 +360,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
my Int $frac := 0;
my Int $base := 0;
if nqp::iseq_i($ch, 46) { # '.'
$pos = nqp::add_i($pos, 1);
++$pos;
$parse := nqp::radix_I($radix, $str, $pos,
nqp::add_i($neg, 4), Int);
$p = nqp::atpos($parse, 2);
Expand All @@ -378,16 +378,16 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
parse_fail "'E' or 'e' style exponent only allowed on decimal (base-10) numbers, not base-$radix"
unless nqp::iseq_i($radix, 10);

$pos = nqp::add_i($pos, 1);
++$pos;
# handle the sign
# XXX TODO: teach radix_I to handle '−' (U+2212) minus?
my int $ch = nqp::islt_i($pos, $eos) && nqp::ord($str, $pos);
my int $neg-e = nqp::if(
nqp::iseq_i($ch, 43), # '+'
nqp::stmts(($pos = nqp::add_i($pos, 1)), 0),
nqp::stmts(++$pos,0),
nqp::if( # '-', '−'
nqp::iseq_i($ch, 45) || nqp::iseq_i($ch, 8722),
nqp::stmts(($pos = nqp::add_i($pos, 1)), 1),
nqp::stmts(++$pos,1),
0,
)
);
Expand All @@ -408,7 +408,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
# get recursive multiplier parsing stupidity)
if nqp::iseq_i($ch, 42)
&& nqp::isne_s(substr($str, $pos, 2), '**') { # '*'
$pos = nqp::add_i($pos, 1);
++$pos;
my $mult_base := parse-simple-number();

parse_fail "'*' multiplier base must be an integer"
Expand All @@ -434,7 +434,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
# Look for radix specifiers
if nqp::iseq_i($ch, 58) { # ':'
# A string of the form :16<FE_ED.F0_0D> or :60[12,34,56]
$pos = nqp::add_i($pos, 1);
++$pos;
$parse := nqp::radix_I(10, $str, $pos, 0, Int);
$p = nqp::atpos($parse, 2);
parse_fail "radix (in decimal) expected after ':'"
Expand All @@ -444,31 +444,31 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
$radix = nqp::atpos($parse, 0);
$ch = nqp::islt_i($pos, $eos) && nqp::ord($str, $pos);
if nqp::iseq_i($ch, 60) { # '<'
$pos = nqp::add_i($pos, 1);
++$pos;

my $result := parse-int-frac-exp();

parse_fail "malformed ':$radix<>' style radix number, expecting '>' after the body"
unless nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 62); # '>'

$pos = nqp::add_i($pos, 1);
++$pos;
return $result;
}
elsif nqp::iseq_i($ch, 171) { # '«'
$pos = nqp::add_i($pos, 1);
++$pos;

my $result := parse-int-frac-exp();

parse_fail "malformed ':$radix«»' style radix number, expecting '»' after the body"
unless nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 187); # '»'

$pos = nqp::add_i($pos, 1);
++$pos;
return $result;
}
elsif nqp::iseq_i($ch, 91) { # '['
$pos = nqp::add_i($pos, 1);
++$pos;
my Int $result := 0;
my Int $digit := 0;
while nqp::islt_i($pos, $eos)
Expand All @@ -484,14 +484,14 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
if nqp::isge_i($digit, $radix);

$result := $result * $radix + $digit;
$pos = nqp::add_i($pos, 1)
if nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 44); # ','
++$pos
if nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 44); # ','
}
parse_fail "malformed ':$radix[]' style radix number, expecting ']' after the body"
unless nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 93); # ']'
$pos = nqp::add_i($pos, 1);
++$pos;

# XXXX: Handle fractions!
# XXXX: Handle exponents!
Expand All @@ -503,14 +503,14 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
}
elsif nqp::iseq_i($ch, 48) # '0'
and $radix = nqp::index(' b o d x',
nqp::substr($str, nqp::add_i($pos, 1), 1))
nqp::substr($str,nqp::add_i($pos,1),1))
and nqp::isge_i($radix, 2) {
# A string starting with 0x, 0d, 0o, or 0b,
# followed by one optional '_'
$pos = nqp::add_i($pos, 2);
$pos = nqp::add_i($pos, 1)
if nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 95); # '_'
++$pos
if nqp::islt_i($pos, $eos)
&& nqp::iseq_i(nqp::ord($str, $pos), 95); # '_'

parse-int-frac-exp();
}
Expand All @@ -533,7 +533,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {

# Check for '/' indicating Rat denominator
if nqp::iseq_i(nqp::ord($str, $pos), 47) { # '/'
$pos = nqp::add_i($pos, 1);
++$pos;
parse_fail "denominator expected after '/'"
unless nqp::islt_i($pos, $eos);

Expand All @@ -557,7 +557,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
if nqp::iseq_i(nqp::ord($str, $pos), 105) { # 'i'
parse_fail "Imaginary component of 'NaN' or 'Inf' must be followed by \\i"
if nqp::isnanorinf($result.Num);
$pos = nqp::add_i($pos, 1);
++$pos;
$result := Complex.new(0, $result);
}
elsif nqp::eqat($str,'\\i',$pos) {
Expand All @@ -577,7 +577,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
if nqp::iseq_i(nqp::ord($str, $pos), 105) { # 'i'
parse_fail "Imaginary component of 'NaN' or 'Inf' must be followed by \\i"
if nqp::isnanorinf($im.Num);
$pos = nqp::add_i($pos, 1);
++$pos;
}
elsif nqp::eqat($str,'\\i',$pos) {
$pos = nqp::add_i($pos, 2);
Expand Down

0 comments on commit 8077ebd

Please sign in to comment.