Allow parsing mixed HTML and PHP#234
Merged
Merged
Conversation
jrfnl
reviewed
Jun 18, 2021
Comment on lines
+16
to
+22
| return array_merge( | ||
| array_values(Tokens::$emptyTokens), | ||
| [ | ||
| T_INLINE_HTML, | ||
| T_CLOSE_TAG, | ||
| ] | ||
| ); |
Collaborator
There was a problem hiding this comment.
Suggested change
| return array_merge( | |
| array_values(Tokens::$emptyTokens), | |
| [ | |
| T_INLINE_HTML, | |
| T_CLOSE_TAG, | |
| ] | |
| ); | |
| $empty = Tokens::$emptyTokens; | |
| $empty[T_INLINE_HTML] = T_INLINE_HTML; | |
| $empty[T_CLOSE_TAG] = T_CLOSE_TAG; | |
| return $empty; |
Array functions like array_merge() and array_values() are "expensive".
Changing it to the above will be more efficient performance + memory-use-wise.
You could even choose to optimize it further like this:
Suggested change
| return array_merge( | |
| array_values(Tokens::$emptyTokens), | |
| [ | |
| T_INLINE_HTML, | |
| T_CLOSE_TAG, | |
| ] | |
| ); | |
| static $empty; | |
| if (isset($empty) === false) { | |
| $empty = Tokens::$emptyTokens; | |
| $empty[T_INLINE_HTML] = T_INLINE_HTML; | |
| $empty[T_CLOSE_TAG] = T_CLOSE_TAG; | |
| } | |
| return $empty; |
It's not as if this compound array will change at any time during the run.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When mixing HTML and PHP, we must ignore the HTML tokens and the closing PHP tokens. This PR alters the parsing to consider them "empty" for the sake of all the functions that skip over empty space. Notably, this allows considering a closing HTML tag as the end of the global scope.
Fixes #232