Repository navigation
perf(liquid-html-parser): drop redundant endPos store when skipping LiquidDoc newlines - #1410
Draft
EvilGenius13 wants to merge 1 commit into
Draft
EvilGenius13 wants to merge 1 commit into
EvilGenius13 wants to merge 1 commit into
Conversation
…iquidDoc newlines
This branch has not been deployed
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.
What are you adding in this PR?
When
collectContentLinesin the LiquidDoc parser reaches a run of blank lines that ends in text, it consumes the run in one loop. That loop storedendPos = this.peek().endon every newline. The store does nothing: the loop only runs when text follows the run, and that next text line always setsendPos = current.endagain before anything reads it. This PR removes the store, which also saves one token read per newline:@EvilGenius13 suggested this in a review comment on #1387: #1387 (comment)
The parsed output doesn't change. A patch changeset for
@shopify/liquid-html-parseris included.Regression test for the blank-line skip
Right after this loop, the parser skips whitespace-only text lines. That skip is still needed, and no existing test failed when it was removed. This PR adds a test under
@prompt(skips the blank line left by a non-breaking space after @prompt). It parses{% doc %}\n@prompt\u00a0\n\nBuild it\n{% enddoc %}and checks that:content.valueis"\n\nBuild it\n"content.position.startis17Both values were recorded on
mainbefore the change. If the blank-line skip is deleted, the test fails withexpected 18 to be 17, because the non-breaking space line becomes the first content line and its leading whitespace moves the start position.What's next? Any followup issues?
None.
Tophatting
These all passed on this branch:
I also deleted the blank-line skip temporarily: only the new test failed (
expected 18 to be 17). Then I restored the skip.Before you deploy
changesetRefs https://github.com/shopify-playground/eg-hydra/issues/17
eg-hydra-issue: https://eg-hydra.quick.shopify.io/#issue/865f8849-492c-4f1a-a27b-bd943bc29ac8