Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rakudo/rakudo
...
head fork: rakudo/rakudo
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on May 30, 2012
@moritz moritz in Str.subst, never produce the whole list of matches
for very long strings this is too memory intensive. not_gerd++
494bd4f
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/core/Str.pm
View
17 src/core/Str.pm
@@ -586,13 +586,19 @@ my class Str does Stringy {
multi method subst($matcher, $replacement,
:ii(:$samecase), :ss(:$samespace),
:$SET_CALLER_DOLLAR_SLASH, *%options) {
- my @matches = self.match($matcher, |%options);
- return self unless @matches;
- return self if @matches == 1 && !@matches[0];
+ my $matches := self.match($matcher, |%options);
+ return self unless $matches;
+ if $matches ~~ Match {
+ $matches := ($matches,).list;
+ }
+ else {
+ $matches := $matches.list;
+ }
my $caller_dollar_slash := pir::find_caller_lex__Ps('$/');
my $prev = 0;
my $result = '';
- for @matches -> $m {
+ while $matches {
+ my $m = $matches.shift;
$result ~= self.substr($prev, $m.from - $prev);
$caller_dollar_slash = $m if $SET_CALLER_DOLLAR_SLASH;
@@ -602,8 +608,7 @@ my class Str does Stringy {
$result ~= $real_replacement;
$prev = $m.to;
}
- my $last = @matches.pop;
- $result ~= self.substr($last.to);
+ $result ~= self.substr($prev);
$result;
}

No commit comments for this range

Something went wrong with that request. Please try again.