Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement step 5 of select_image_source #21215
Conversation
highfive
commented
Jul 19, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jul 19, 2018
|
r? @jdm |
|
@bors-servo try |
Implement step 5 of select_image_source <!-- Please describe your changes on the following line: --> This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density) In case of no device, maximum density source is selected. --- <!-- 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 #11416 <!-- Either: --> - [x] These changes do not require tests because tests are already present <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/21215) <!-- Reviewable:end -->
|
|
|
That's #20734. |
|
Alright, this issue seems to be a problem to everyone. How do you solve it |
|
My only suggestion here is to use iterators for these loops instead of explicit array indexes when possible. |
| max_den = den; | ||
| max_index = current_index; | ||
| } | ||
| current_index = current_index + 1; |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 20, 2018
•
Member
We can write this more idiomatically as:
let mut max = (0f64, 0);
for image_source in &source_set.image_sources {
if repeat_indices.contains(&index) {
continue;
}
let den = image_source.descriptor.den.unwrap();
if max.0 < den {
max = (den, img_sources.len());
}
img_sources.push(image_source);
}
This comment has been minimized.
This comment has been minimized.
nupurbaghel
Jul 20, 2018
Author
Contributor
Do we have to generate index here too by enumerating like the next suggestion ?
This comment has been minimized.
This comment has been minimized.
| let device = document_from_node(self).device(); | ||
| if device.is_some() { | ||
| let device_den: f64 = device.unwrap().device_pixel_ratio().get().into(); | ||
| for outer_index in 0..img_sources.len() { |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 20, 2018
Member
We can write this more idiomatically as:
if let Some(device) = device {
let device_den = device.device_pixel_ratio().get() as f64;
let mut best_candidate = max;
for (index, image_source) in img_sources.iter().enumerate() {
let current_den = image_source.descriptor.den.unwrap();
if current_den < best_candidate.0 && current_den >= device_den {
best_candidate = (current_den, index);
}
}
}e45af10
to
c881c2a
|
Made the suggested changes |
|
@bors-servo r+ |
|
|
Implement step 5 of select_image_source <!-- Please describe your changes on the following line: --> This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density) In case of no device, maximum density source is selected. --- <!-- 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 #11416 <!-- Either: --> - [x] These changes do not require tests because tests are already present <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/21215) <!-- Reviewable:end -->
|
|
nupurbaghel commentedJul 19, 2018
•
edited by SimonSapin
This step is responsible for selecting an image source based on user agent's environment( closest value which is greater than user's pixel density)
In case of no device, maximum density source is selected.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is