Skip to content

perf: make parse_scheme slightly faster #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

dsherret
Copy link
Contributor

@dsherret dsherret commented Feb 7, 2025

Avoids a check that's already covered by another check and avoids doing a is_ascii_uppercase() check in to_ascii_lowercase() when we know the character is lowercase.

Before:

test short          ... bench:         189 ns/iter (+/- 6) = 132 MB/s

After:

test short          ... bench:         182 ns/iter (+/- 5) = 137 MB/s

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@79ff014). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1025   +/-   ##
=======================================
  Coverage        ?   79.98%           
=======================================
  Files           ?       24           
  Lines           ?     4287           
  Branches        ?        0           
=======================================
  Hits            ?     3429           
  Misses          ?      858           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -398,15 +398,14 @@ impl<'a> Parser<'a> {
}

pub fn parse_scheme<'i>(&mut self, mut input: Input<'i>) -> Result<Input<'i>, ()> {
if input.is_empty() || !input.starts_with(ascii_alpha) {
if !input.starts_with(ascii_alpha) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment that starts_with will also fail for empty strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment and unit test.

@dsherret dsherret requested a review from lucacasonato February 8, 2025 13:32
@valenting valenting added this pull request to the merge queue Feb 13, 2025
Merged via the queue into servo:main with commit 4b9f1e6 Feb 13, 2025
18 checks passed
@dsherret dsherret deleted the perf_parse_scheme branch February 13, 2025 13:00
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.

3 participants