summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2012-08-24 16:17:47 +0100
committerDavid Mitchell <davem@iabyn.com>2012-09-08 15:42:07 +0100
commita41aa44d9dc4a3ba586d871754bd11137bdc37a2 (patch)
treecf9777a88b54f956185fc04cf3b93adfe64692ef /pp_hot.c
parent9414be0160a1f343d4ae75ec161fec610da39c84 (diff)
downloadperl-a41aa44d9dc4a3ba586d871754bd11137bdc37a2.tar.gz
stop $foo =~ /(bar)/g skipping copy
Normally in the presence of captures, a successful regex execution makes a copy of the matched string, so that $1 et al give the right value even if the original string is changed; i.e. $foo =~ /(123)/g; $foo = "bar"; is("$1", "123"); Until now that test would fail, because perl used to skip the copy for the scalar /(...)/g case (but not the C<$&; //g> case). This was to avoid a huge slowdown in code like the following: $x = 'x' x 1_000_000; 1 while $x =~ /(.)/g; which would otherwise end up copying a 1Mb string a million times. Now that (with the last commit but one) we copy only the required substring of the original string (a 1-byte substring in the above example), we can remove this fast-but-incorrect hack.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 91958ac441..6530ae5b4d 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1319,12 +1319,7 @@ PP(pp_match)
}
}
}
- /* XXX: comment out !global get safe $1 vars after a
- match, BUT be aware that this leads to dramatic slowdowns on
- /g matches against large strings. So far a solution to this problem
- appears to be quite tricky.
- Test for the unsafe vars are TODO for now. */
- if ( (!global && RX_NPARENS(rx))
+ if ( RX_NPARENS(rx)
|| PL_sawampersand
|| SvTEMP(TARG)
|| SvAMAGIC(TARG)