Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading