Skip to content

Commit ee735e8

Browse files
author
bors-servo
authored
Auto merge of #110 - emilio:data-uri, r=SimonSapin
Don't use utf8 logic to parse unquoted urls. Since it's not needed, and it's noticeable when parsing large data-uris, like servo/servo#13778. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/110) <!-- Reviewable:end -->
2 parents b778697 + 673623f commit ee735e8

File tree

5 files changed

+160
-79
lines changed

5 files changed

+160
-79
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "cssparser"
4-
version = "0.7.0"
4+
version = "0.7.1"
55
authors = [ "Simon Sapin <[email protected]>" ]
66

77
description = "Rust implementation of CSS Syntax Level 3"
@@ -25,3 +25,4 @@ serde = {version = ">=0.6.6, <0.9", optional = true}
2525
[features]
2626
serde-serialization = [ "serde" ]
2727
heap_size = [ "heapsize" ]
28+
bench = []

src/big-data-url.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![crate_name = "cssparser"]
66
#![crate_type = "rlib"]
77

8+
#![cfg_attr(feature = "bench", feature(test))]
89
#![deny(missing_docs)]
910

1011
/*!

src/tests.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
#[cfg(feature = "bench")]
6+
extern crate test;
7+
58
use std::borrow::Cow::{self, Borrowed};
69
use std::fs::File;
710
use std::io::{self, Write};
@@ -10,6 +13,9 @@ use std::process::Command;
1013
use rustc_serialize::json::{self, Json, ToJson};
1114
use tempdir::TempDir;
1215

16+
#[cfg(feature = "bench")]
17+
use self::test::Bencher;
18+
1319
use encoding::label::encoding_from_whatwg_label;
1420

1521
use super::{Parser, Delimiter, Token, NumericValue, PercentageValue, SourceLocation,
@@ -576,6 +582,24 @@ impl ToJson for Color {
576582
}
577583
}
578584

585+
#[cfg(feature = "bench")]
586+
const BACKGROUND_IMAGE: &'static str = include_str!("big-data-url.css");
587+
588+
#[cfg(feature = "bench")]
589+
#[bench]
590+
fn unquoted_url(b: &mut Bencher) {
591+
b.iter(|| {
592+
let mut input = Parser::new(BACKGROUND_IMAGE);
593+
input.look_for_var_functions();
594+
595+
let result = input.try(|input| input.expect_url());
596+
597+
assert!(result.is_ok());
598+
599+
input.seen_var_functions();
600+
(result.is_ok(), input.seen_var_functions())
601+
})
602+
}
579603

580604
struct JsonParser;
581605

@@ -667,7 +691,6 @@ fn component_values_to_json(input: &mut Parser) -> Vec<Json> {
667691
values
668692
}
669693

670-
671694
fn one_component_value_to_json(token: Token, input: &mut Parser) -> Json {
672695
fn numeric(value: NumericValue) -> Vec<json::Json> {
673696
vec![

0 commit comments

Comments
 (0)