Speed up do_classes_matches?#649
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a performance optimization for CSS class matching by adding a guard check using String.contains?/2 before performing the more expensive String.split/2 operation. If the class attribute doesn't contain the target class substring, the function returns false immediately, avoiding unnecessary string splitting and enumeration.
- Adds
String.contains?/2guard check beforeString.split/2in single-class matching - Maintains correctness by still performing full validation when substring is present
- Targets the
do_classes_matches?/2function for single-class selectors
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
@preciz good call. Thank you! |
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.
Introduced a guard check using
String.contains?/2.If the class attribute does not contain the target class substring, we return false immediately, bypassing the expensiveString.split/2operation.There is an average 1.5x speed up.
Bench script: