@@ -34,29 +34,42 @@ 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+ {
58+ $( maxlen = const_usize_max( maxlen, $pattern. len( ) ) ; ) +
59+ }
60+ ) +
61+ maxlen
62+ } ;
63+
64+ $crate:: _cssparser_internal_to_lowercase!( $input, MAX_LENGTH => lowercase) ;
5365 // "A" is a short string that we know is different for every string pattern,
5466 // since we’ve verified that none of them include ASCII upper case letters.
5567 match lowercase. unwrap_or( "A" ) {
5668 $(
5769 $( #[ $meta] ) *
5870 $( $pattern ) |+ $( if $guard ) ? => $then,
5971 ) +
72+ $( _ => $fallback, ) ?
6073 }
6174 }
6275 } ;
@@ -95,13 +108,24 @@ macro_rules! ascii_case_insensitive_phf_map {
95108 ( $name: ident -> $ValueType: ty = { $( $key: tt => $value: expr, ) + } ) => {
96109 use $crate:: _cssparser_internal_phf as phf;
97110
98- // See macro above for context.
99- mod cssparser_internal {
100- $crate:: _cssparser_internal_max_len! {
101- $( $key ) +
111+ #[ inline( always) ]
112+ const fn const_usize_max( a: usize , b: usize ) -> usize {
113+ if a > b {
114+ a
115+ } else {
116+ b
102117 }
103118 }
104119
120+ const MAX_LENGTH : usize = {
121+ let mut maxlen : usize = 0 ;
122+ $(
123+ // {} is necessary to work around "[E0658]: attributes on expressions are experimental"
124+ { maxlen = const_usize_max( maxlen, ( $key) . len( ) ) ; }
125+ ) +
126+ maxlen
127+ } ;
128+
105129 static MAP : phf:: Map <& ' static str , $ValueType> = phf:: phf_map! {
106130 $(
107131 $key => $value,
@@ -122,7 +146,7 @@ macro_rules! ascii_case_insensitive_phf_map {
122146 }
123147
124148 fn get( input: & str ) -> Option <& ' static $ValueType> {
125- $crate:: _cssparser_internal_to_lowercase!( input, cssparser_internal :: MAX_LENGTH => lowercase) ;
149+ $crate:: _cssparser_internal_to_lowercase!( input, MAX_LENGTH => lowercase) ;
126150 MAP . get( lowercase?)
127151 }
128152 }
0 commit comments