Skip to content
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

Reduce small string allocations with simple char counting #935

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,13 @@
input
.clone()
.take_while(|&c| matches!(c, '/' | '\\'))
.collect::<String>()
!= "//"
.take(3)

Check warning on line 453 in url/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

url/src/parser.rs#L453

Added line #L453 was not covered by tests
.fold((0, 0), |(slashes, backslashes), c| match c {
'/' => (slashes + 1, backslashes),
'\\' => (slashes, backslashes + 1),
_ => unreachable!(),

Check warning on line 457 in url/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

url/src/parser.rs#L456-L457

Added lines #L456 - L457 were not covered by tests
})
!= (2, 0)

Check warning on line 459 in url/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

url/src/parser.rs#L459

Added line #L459 was not covered by tests
});
self.after_double_slash(remaining, scheme_type, scheme_end)
}
Expand Down Expand Up @@ -754,8 +759,13 @@
input
.clone()
.take_while(|&c| matches!(c, '/' | '\\'))
.collect::<String>()
!= "//"
.take(3)
.fold((0, 0), |(slashes, backslashes), c| match c {
'/' => (slashes + 1, backslashes),
'\\' => (slashes, backslashes + 1),
_ => unreachable!(),

Check warning on line 766 in url/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

url/src/parser.rs#L762-L766

Added lines #L762 - L766 were not covered by tests
})
!= (2, 0)

Check warning on line 768 in url/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

url/src/parser.rs#L768

Added line #L768 was not covered by tests
});
let scheme_end = base_url.scheme_end;
debug_assert!(base_url.byte_at(scheme_end) == b':');
Expand Down
Loading