Repository navigation
Refactor HSTSList to use HashMap - #14794
Conversation
|
Heads up! This PR modifies the following files:
|
| e.matches_domain(host) | ||
| let base_domain = reg_host(host); | ||
|
|
||
| match self.entries_map.get(&base_domain) { |
There was a problem hiding this comment.
nit: You can use:
self.entries_map.get(&base_domain).map_or(false, |entries| {
// ...
})To save a bit of indentation. Also applies below.
emilio
left a comment
There was a problem hiding this comment.
Looks good to me once those comments are addressed, thanks for doing this! :)
| .ok() | ||
| .and_then(|c| decode(c).ok()) | ||
| .and_then(|c| decode(c).ok()); | ||
| if hsts_entries.is_some() { |
There was a problem hiding this comment.
nit: Use:
hsts_entries.map(|entries| {
//
})Instead.
| } | ||
| } | ||
|
|
||
| fn reg_host<'a>(url: &'a str) -> String { |
There was a problem hiding this comment.
I don't think this is needed? Just use reg_suffix, and when needed do to_owned or similar, but you don't need a String all the time.
There was a problem hiding this comment.
Thanks, I had to add let host = entry.host.clone(); to solve borrowing issue is this fine?
Refactored HSTSList to use HashMap, where the key of HashMap is the base domain. Every time when we check if a host is secure, we find the base domain of the host and get a vector of HSTS entries associated with the base domain. While this will not give O(1) look up time, we would have a smaller list to iterate for every lookup. I have added one unit test to validate HashMap changes.
|
@bors-servo r+ Yeah, it's ok. Thanks for doing this! :) |
|
📌 Commit 6a14349 has been approved by |
Refactor HSTSList to use HashMap Refactored HSTSList to use HashMap, where the key of HashMap is the base domain. Every time when we check if a host is secure, we find the base domain of the host and get a vector of HSTS entries associated with the base domain. While this will not give O(1) look up time, we would have a smaller list to iterate for every lookup. I have added one unit test to validate `HashMap` changes. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14756 <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14794) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-gnu-dev, windows-msvc-dev |
|
Thanks @emilio |
Refactored HSTSList to use HashMap, where the key of HashMap is the base domain. Every time when we check if a host is secure, we find the base domain of the host and get a vector of HSTS entries associated with the base domain.
While this will not give O(1) look up time, we would have a smaller list to iterate for every lookup. I have added one unit test to validate
HashMapchanges../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is