Re: [Perl/perl5] 502da7: make /p a no-op
[email protected] (Michael Conrad) Fri, 13 Feb 2026 18:35:21 -0500
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On 2/12/26 14:56, Leon Timmermans wrote: > On Thu, Feb 12, 2026 at 10:57 AM demerphq <[email protected]> wrote: > > You sure this doesn't make while /g matches go quadratic? Lastly I > checked /p still matters for while/g -- the COW stuff doesn't > always kick in: Not every string can be COWed. Iirc strings > returned from <>/readline aren't COWed. > > > I was recently made aware of another related issue: string from > File::Map can't COW[1]. And given that they can be very very large > that is a serious problem. I don't think PL_sawampersand is as useless > as some people thought it was. > > Leon > > 1: https://rt.cpan.org/Ticket/Display.html?id=167860 Related, I discovered recently that there's no way to apply the regex engine to a buffer that I don't want Perl to hold onto and still get capture information. (It can be applied without capturing for a simple true/false result, but that didn't help with Crypt::SecretBuffer) I think it could be a useful start just to change the internal XS API such that there is a way to apply a regex to a caller-owned buffer and then ask the regex engine to describe the capture boundaries as byte offsets without making any copies of the underlying buffer. Even better, if the regex engine could be supplied some kind of "capture results" struct to fill in, and then the caller could decide to use that however they wanted. Then maybe there would be one global &PL_regex_captures which, when updated, would affect all the magic variables available to the script. This would give XS code a new method to use the regex engine with less overhead and without touching any of the globals. It would also pave the way for a user-facing feature like all the other languages have where you get a "match" result object from applying their regex engine: var result= "string".match(/regex/); If perl were to add that as say, $result= $foo =~ /regex/r; # return match result object and the result object only contains @- and @+ offsets to be used in substr by the caller, then the copying problem is solved for new code that intentionally decides to avoid it. -Mike C.