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

WIP #17808

Closed
wants to merge 5 commits into from
Closed

WIP #17808

Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Parse Sizes Attribute

  • Loading branch information
Rakhisharma committed Sep 21, 2017
commit f4321b52f91facf45858af410e51823de213ebe3
@@ -798,7 +798,6 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
pub fn parse_a_sizes_attribute(input: DOMString, width: Option<u32>) -> Vec<Size> {

This comment has been minimized.

Copy link
@jdm

jdm Aug 31, 2017

Member

Add a comment like // https://html.spec.whatwg.org/multipage/#parse-a-sizes-attribute so it's clear which algorithm this is based on.

let mut sizes = Vec::<Size>::new();
let unparsed_sizes = input.split(',').collect::<Vec<_>>();

for unparsed_size in &unparsed_sizes {

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Sep 24, 2017

Member

Since unparsed_sizes is used only in the loop, let's iterate on input.split directly (which avoids an iteration and vector allocation).

This comment has been minimized.

Copy link
@Rakhisharma

Rakhisharma Sep 25, 2017

Author Contributor

Not sure what you want me to do here. Would you please elaborate little more. Thanks :)

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Sep 25, 2017

Member

I meant,

for unparsed_size in input.split(',') {

This way, we perform lazy iteration.

let whitespace = unparsed_size.chars().rev().take_while(|c| char::is_whitespace(*c)).count();
let trimmed: String = unparsed_size.chars().take(unparsed_size.chars().count() - whitespace).collect();
@@ -814,7 +813,6 @@ pub fn parse_a_sizes_attribute(input: DOMString, width: Option<u32>) -> Vec<Size
QuirksMode::NoQuirks);
let mut parser = Parser::new(&mut input);
let length = parser.try(|i| Length::parse_non_negative(&context, i));
println!("\n{:?}", length);
match length {
Ok(len) => sizes.push(Size {
length: len,
@@ -100,4 +100,4 @@ fn extra_whitespace() {
let a = &[size, size1];
assert_eq!(parse_a_sizes_attribute(DOMString::from("(max-width: 900px) 1000px, (max-width: 900px) 50px"),
None), a);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.