2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
+ #[ cfg( feature = "bench" ) ]
6
+ extern crate test;
7
+
5
8
use std:: borrow:: Cow :: { self , Borrowed } ;
6
9
use std:: fs:: File ;
7
10
use std:: io:: { self , Write } ;
@@ -10,6 +13,9 @@ use std::process::Command;
10
13
use rustc_serialize:: json:: { self , Json , ToJson } ;
11
14
use tempdir:: TempDir ;
12
15
16
+ #[ cfg( feature = "bench" ) ]
17
+ use self :: test:: Bencher ;
18
+
13
19
use encoding:: label:: encoding_from_whatwg_label;
14
20
15
21
use super :: { Parser , Delimiter , Token , NumericValue , PercentageValue , SourceLocation ,
@@ -576,6 +582,24 @@ impl ToJson for Color {
576
582
}
577
583
}
578
584
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
+ }
579
603
580
604
struct JsonParser ;
581
605
@@ -667,7 +691,6 @@ fn component_values_to_json(input: &mut Parser) -> Vec<Json> {
667
691
values
668
692
}
669
693
670
-
671
694
fn one_component_value_to_json ( token : Token , input : & mut Parser ) -> Json {
672
695
fn numeric ( value : NumericValue ) -> Vec < json:: Json > {
673
696
vec ! [
0 commit comments