in reply to An optimization of last resort: eliminate capturing from your regexps
I wonder... A switch could be added that would tell perl that you commit to not modifying the string before utilizing $1. Then the memcopy would be unnecessary. That way you could say
$str =~ /Hulk hate (\w+)/k;
And get the same effect. Of course the demons that would fly out of your nose if you said:
if ($str =~ /Hulk hate (\w+)/k) { $str='demons!'; print $1; # could and probably would throw fatal error. }
Would be your problem...
BTW, if it isnt clear, this is the reason the memcpy is needed.
Alternatively, perhaps magic could be introduced to $str so that the memcpy would only happen if $str was modified while the match vars pointed at it...
A last possibility would be to not do the memcpy if the string was RO. Then you could by hand readonly the string, do the match, use $1 and then when and if you needed to modify the string undo the RO.
I guess another variant could be that the /k would result in no copy, and an understanding that accessing $1 et all would be a fatal error while that regex was the last used. However the @- @+ arrays would be populated. Its just the user would be expected to do the substring operations by hand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: An optimization of last resort: eliminate capturing from your regexps
by tilly (Archbishop) on Jul 12, 2006 at 01:09 UTC | |
by tye (Sage) on Jul 12, 2006 at 02:51 UTC | |
|
Re^2: An optimization of last resort: eliminate capturing from your regexps
by Aristotle (Chancellor) on Jul 24, 2006 at 22:04 UTC | |
by diotalevi (Canon) on Jul 24, 2006 at 23:06 UTC | |
by Aristotle (Chancellor) on Jul 24, 2006 at 23:31 UTC | |
by diotalevi (Canon) on Jul 25, 2006 at 02:34 UTC |