Skip to content

Conversation

@khwilliamson
Copy link
Contributor

This p.r. add a quick lookup for characters that may have magic with them, allowing for quickly ruling out any others. This eliminates the need for some special tests that were done for such ruling out.

It also refactors to eliminate duplicated code.

  • This set of changes does not require a perldelta entry.

If you trace the execution of what happens to 0 length input, it relies
on a NUL terminator in the string, and does nothing.  Simply return
false immediately instead.
Some characters have special meaning to gv_magicalize().  This commit
marks those in PL_charclass.  This allows the next commit to more
quickly than currently rule them out during processing.
This uses the data structure introduced in the previous commit to
quickly test the input first character.  If it isn't a potential magical
one, it could apply to CORE, so move the block that checks for that to
here, eliminating a conditional.  In either case, no need to look further.
The previous commit moved a block, so two of these aren't necessary, and
the final one can be removed by adding an else
This is just to make the next commit differences a bit smaller
This refactors to eliminate redundant code.  Some things are magical
only if we are using the main stash; others in any stash; one only in
PL_debstash.

Previously, the switches were structured thusly:
 1) if we aren't using the main stash, handle things not requiring the
        main stash
 2) if we are using the main stash, handle all len > 1 things that can
        be in the main stash.  This duplicates much of item 1)
 3) if we are using the main stash, handle all len == 1 things that can
        be in the main stash.  This duplicates some of item 1)

The new structure is
 if (len > 1) {
    1) handle len > 1 things not requiring main stash, regardless of the
       stash we are in
    2) handle len > 1 things requiring main stash
 } else {
    3) handle len == 1 things, regardless of the stash we are in.
 }

This removes the duplicated code.

The case for 'a' and 'b' are special.  When 'a' stands for "args" it is
len > 1 and that is handled in 1).

But 'a' can also mean a single character, as 'b' always does.  These
cases are handled in 3).  These are the only two len == 1 characters
that don't have to be in the main package, so there is an extra
conditional clause to allow that.
This indents things to nicely align vertically and moves some braces in
the process
These two switch() statements handle magic names.  We now have a quick
way to determine if the first character of a name is magic.  Assert that
the cases of the switch match.  This will tell us if something gets
out-of-sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant