Skip to content

Commit

Permalink
Auto merge of #110 - emilio:data-uri, r=SimonSapin
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Nov 1, 2016
2 parents b778697 + 673623f commit ee735e8
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 79 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
@@ -1,7 +1,7 @@
[package]

name = "cssparser"
version = "0.7.0"
version = "0.7.1"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand All @@ -25,3 +25,4 @@ serde = {version = ">=0.6.6, <0.9", optional = true}
[features]
serde-serialization = [ "serde" ]
heap_size = [ "heapsize" ]
bench = []
1 change: 1 addition & 0 deletions src/big-data-url.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -5,6 +5,7 @@
#![crate_name = "cssparser"]
#![crate_type = "rlib"]

#![cfg_attr(feature = "bench", feature(test))]
#![deny(missing_docs)]

/*!
Expand Down
25 changes: 24 additions & 1 deletion src/tests.rs
Expand Up @@ -2,6 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(feature = "bench")]
extern crate test;

use std::borrow::Cow::{self, Borrowed};
use std::fs::File;
use std::io::{self, Write};
Expand All @@ -10,6 +13,9 @@ use std::process::Command;
use rustc_serialize::json::{self, Json, ToJson};
use tempdir::TempDir;

#[cfg(feature = "bench")]
use self::test::Bencher;

use encoding::label::encoding_from_whatwg_label;

use super::{Parser, Delimiter, Token, NumericValue, PercentageValue, SourceLocation,
Expand Down Expand Up @@ -576,6 +582,24 @@ impl ToJson for Color {
}
}

#[cfg(feature = "bench")]
const BACKGROUND_IMAGE: &'static str = include_str!("big-data-url.css");

#[cfg(feature = "bench")]
#[bench]
fn unquoted_url(b: &mut Bencher) {
b.iter(|| {
let mut input = Parser::new(BACKGROUND_IMAGE);
input.look_for_var_functions();

let result = input.try(|input| input.expect_url());

assert!(result.is_ok());

input.seen_var_functions();
(result.is_ok(), input.seen_var_functions())
})
}

struct JsonParser;

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


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

0 comments on commit ee735e8

Please sign in to comment.