-
Notifications
You must be signed in to change notification settings - Fork 136
Fix accidentally quadratic algorithm #102
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
Conversation
@@ -409,7 +409,7 @@ fn line_numbers() { | |||
assert_eq!(input.next_including_whitespace(), Ok(Token::Ident(Borrowed("foo")))); | |||
assert_eq!(input.current_source_location(), SourceLocation { line: 1, column: 4 }); | |||
assert_eq!(input.next_including_whitespace(), Ok(Token::WhiteSpace(" "))); | |||
assert_eq!(input.current_source_location(), SourceLocation { line: 1, column: 5 }); | |||
// assert_eq!(input.current_source_location(), SourceLocation { line: 1, column: 5 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or keep, but don't comment it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, I didn’t mean to commit that. Reverted.
@bors-servo: r+ |
📌 Commit d1eefdf has been approved by |
Fix accidentally quadratic algorithm `Tokenize::source_location` takes an "position" counting UTF-8 bytes since the start of the stylesheet and returns a "location" made of a line number and column number. To avoid counting lines from the start every time, it saves some results after each call. Previously we would only save the position of the last known line break, so calling source_location() for name positions within a single long line would keep searching from that point for the next line break and therefore take O(n²) time. Very long lines can easily happen when a CSS minifier is used. We now save the full (line, column) result from the last call. See servo/servo#9897 (comment) and servo/servo#9897 (comment) r? @jdm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/102) <!-- Reviewable:end -->
💔 Test failed - travis |
☔ The latest upstream changes (presumably #99) made this pull request unmergeable. Please resolve the merge conflicts. |
Previously we would only save the position of the last known line break, so calling source_location() for name positions within a single long line would keep searching from that point for the next line break and therefore take O(n²) time. We now save the full (line, column) result from the last call. servo/servo#9897 (comment) servo/servo#9897 (comment)
Rebased. @bors-servo r=jdm Previous failure was |
📌 Commit 375ad58 has been approved by |
Fix accidentally quadratic algorithm `Tokenize::source_location` takes an "position" counting UTF-8 bytes since the start of the stylesheet and returns a "location" made of a line number and column number. To avoid counting lines from the start every time, it saves some results after each call. Previously we would only save the position of the last known line break, so calling source_location() for name positions within a single long line would keep searching from that point for the next line break and therefore take O(n²) time. Very long lines can easily happen when a CSS minifier is used. We now save the full (line, column) result from the last call. See servo/servo#9897 (comment) and servo/servo#9897 (comment) r? @jdm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/102) <!-- Reviewable:end -->
☀️ Test successful - travis |
Published v0.5.5 on crates.io |
Tokenize::source_location
takes an "position" counting UTF-8 bytes since the start of the stylesheet and returns a "location" made of a line number and column number. To avoid counting lines from the start every time, it saves some results after each call.Previously we would only save the position of the last known line break, so calling source_location() for name positions within a single long line would keep searching from that point for the next line break and therefore take O(n²) time.
Very long lines can easily happen when a CSS minifier is used.
We now save the full (line, column) result from the last call.
See servo/servo#9897 (comment) and servo/servo#9897 (comment)
r? @jdm
This change is