@@ -34,29 +34,40 @@ macro_rules! match_ignore_ascii_case {
3434 ( $input: expr,
3535 $(
3636 $( #[ $meta: meta] ) *
37- $( $ pattern: pat ) |+ $( if $guard: expr ) ? => $then: expr
37+ $pattern: literal $( if $guard: expr ) ? => $then: expr
3838 ) ,+
39+ $( , _ => $fallback: expr) ?
3940 $( , ) ?
4041 ) => {
4142 {
42- // This dummy module works around the feature gate
43- // `error[E0658]: procedural macros cannot be expanded to statements`
44- // by forcing the macro to be in an item context
45- // rather than expression/statement context,
46- // even though the macro only expands to items.
47- mod cssparser_internal {
48- $crate:: _cssparser_internal_max_len! {
49- $( $( $pattern ) + ) +
43+ #[ inline( always) ]
44+ const fn const_usize_max( a: usize , b: usize ) -> usize {
45+ if a > b {
46+ a
47+ } else {
48+ b
5049 }
5150 }
52- $crate:: _cssparser_internal_to_lowercase!( $input, cssparser_internal:: MAX_LENGTH => lowercase) ;
51+
52+ const MAX_LENGTH : usize = {
53+ let mut maxlen : usize = 0 ;
54+ $(
55+ $( #[ $meta] ) *
56+ // {} is necessary to work around "[E0658]: attributes on expressions are experimental"
57+ { maxlen = const_usize_max( maxlen, $pattern. len( ) ) ; }
58+ ) +
59+ maxlen
60+ } ;
61+
62+ $crate:: _cssparser_internal_to_lowercase!( $input, MAX_LENGTH => lowercase) ;
5363 // "A" is a short string that we know is different for every string pattern,
5464 // since we’ve verified that none of them include ASCII upper case letters.
5565 match lowercase. unwrap_or( "A" ) {
5666 $(
5767 $( #[ $meta] ) *
58- $( $ pattern ) |+ $( if $guard ) ? => $then,
68+ $pattern $( if $guard ) ? => $then,
5969 ) +
70+ $( _ => $fallback, ) ?
6071 }
6172 }
6273 } ;
@@ -95,13 +106,24 @@ macro_rules! ascii_case_insensitive_phf_map {
95106 ( $name: ident -> $ValueType: ty = { $( $key: tt => $value: expr, ) + } ) => {
96107 use $crate:: _cssparser_internal_phf as phf;
97108
98- // See macro above for context.
99- mod cssparser_internal {
100- $crate:: _cssparser_internal_max_len! {
101- $( $key ) +
109+ #[ inline( always) ]
110+ const fn const_usize_max( a: usize , b: usize ) -> usize {
111+ if a > b {
112+ a
113+ } else {
114+ b
102115 }
103116 }
104117
118+ const MAX_LENGTH : usize = {
119+ let mut maxlen : usize = 0 ;
120+ $(
121+ // {} is necessary to work around "[E0658]: attributes on expressions are experimental"
122+ { maxlen = const_usize_max( maxlen, ( $key) . len( ) ) ; }
123+ ) +
124+ maxlen
125+ } ;
126+
105127 static MAP : phf:: Map <& ' static str , $ValueType> = phf:: phf_map! {
106128 $(
107129 $key => $value,
@@ -122,7 +144,7 @@ macro_rules! ascii_case_insensitive_phf_map {
122144 }
123145
124146 fn get( input: & str ) -> Option <& ' static $ValueType> {
125- $crate:: _cssparser_internal_to_lowercase!( input, cssparser_internal :: MAX_LENGTH => lowercase) ;
147+ $crate:: _cssparser_internal_to_lowercase!( input, MAX_LENGTH => lowercase) ;
126148 MAP . get( lowercase?)
127149 }
128150 }
0 commit comments