Trouble is, either of those cause copying of the referenced substring. Effectively just giving you a reference to an anonymous scalar that is a copy of the substring. You might just as well do:
my $substr = substr $bigstring, $start, $length; func( \$substr );
The purpose of taking a substr ref was to avoid copying large chunks of large string, and allow the large string to be modified in place via that reference.
That said. It seems that taking an (lvalue) substr ref also also triggers copying these days. Albeit with attached magic that means that changes made to the copy also get applied to the original substring. Which is a bit cockeyed.
It never used to, but obviously has for some time--at least since 5.8.6. I'm surprised that I've never noticed it before now. It kind of devalues the purpose of taking a reference to a substring. Methinks whomever made the change did not really get Lvalue refs.
I feel the need to write some XS to (again), give me the ability to to pass a reference to a substring around with causing that substring to be copied.
In reply to Re^2: Access via substr refs 2000 times slower
by BrowserUk
in thread Access via substr refs 2000 times slower
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |