http://www.perlmonks.org?node_id=11121770


in reply to What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff

Eliminate keyword 'given' and treat for(scalar) as a switch statement.

You can already do that.

Disable smart marching by default.

At this point, when is virtually an alias for if. It's rather pointless.

Interpreter should flag as an error if no $_ used in when construct to allow optimization

eh? How does being force to use $_ add opportunities for optimization?

  • Comment on Re: What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff
by likbez (Sexton) on Sep 17, 2020 at 06:11 UTC
    eh? How does being force to use $_ add opportunities for optimization?
    Theoretically the fact that there are several comparisons allows to make comparison to $_ with long strings faster (say more then 64 characters long). If the switch contains several "when" branches with string constants you can pre-compute hash of them and first compare a hash of $_ with hash of the constant and only if hash matches perform full comparison: you need to compute a single hash of $_ for all comparisons. If all "when" branches represent search without meta characters you can pre-compute a table via Knuth-Morris-Pratt for strings search.