Skip Menu |

This queue is for tickets about the CSS-SAC CPAN distribution.

Report information
The Basics
Id: 53943
Status: new
Priority: 0/
Queue: CSS-SAC

People
Owner: Nobody in particular
Requestors: scop [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.08
Fixed in: (no value)



Subject: Avoid regex recompilation
The attached patch provides a measurable performance improvement by avoiding recompilation of regexps.
Subject: o.diff
--- SAC.pm~ 2008-07-05 22:44:20.000000000 +0300 +++ SAC.pm 2010-01-23 13:55:04.000000000 +0200 @@ -382,7 +382,7 @@ elsif ($css =~ s/^\s*\@page\s+//i) { warn "[SAC] parsing page\n" if DEBUG; # grab the name and pseudo-page if they're there - $css =~ s/^($RE_IDENT)?\s*(?::($RE_IDENT))?//; + $css =~ s/^($RE_IDENT)?\s*(?::($RE_IDENT))?//o; my ($name,$pseudo) = ($1,$2); # parse the block @@ -401,7 +401,7 @@ warn "[SAC] parsing unknown at rule ($css)\n" if DEBUG; # take off the @rule first - $css =~ s/^\s*(\@$RE_IDENT\s*)//; + $css =~ s/^\s*(\@$RE_IDENT\s*)//o; $at_rule .= $1; # then grab whatever is not a block @@ -493,7 +493,7 @@ return unless $$css =~ s/^\@charset\s+//i; # extract the string - if ($$css =~ s/^($RE_STRING)\s*;//) { + if ($$css =~ s/^($RE_STRING)\s*;//o) { my $charset = $1; $charset =~ s/^(?:'|")//; #" $charset =~ s/(?:'|")$//; #' @@ -526,14 +526,14 @@ # first get the uri my $uri; if ($$css =~ s/^url\(//) { - $$css =~ s/^((?:$RE_STRING)|([^\)]*))\s*//; + $$css =~ s/^((?:$RE_STRING)|([^\)]*))\s*//o; $uri = $1; $uri =~ s/^(?:'|")//; # " $uri =~ s/(?:'|")$//; # ' $$css =~ s/^\)//; } else { - $$css =~ s/^($RE_STRING)//; + $$css =~ s/^($RE_STRING)//o; $uri = $1; $uri =~ s/^(?:'|")//; #" $uri =~ s/(?:'|")$//; #' @@ -574,20 +574,20 @@ while ($$css =~ s/^\s*\@namespace\s+//i) { my ($prefix,$uri); # first get the prefix - if ($$css !~ /^url\(/ and $$css =~ s/^($RE_IDENT)\s+//) { + if ($$css !~ /^url\(/ and $$css =~ s/^($RE_IDENT)\s+//o) { $prefix = $1; } # then get the uri if ($$css =~ s/^url\(//) { - $$css =~ s/^((?:$RE_STRING)|([^\)]*))\s*//; + $$css =~ s/^((?:$RE_STRING)|([^\)]*))\s*//o; $uri = $1; $uri =~ s/^(?:'|")//; # " $uri =~ s/(?:'|")$//; # ' $$css =~ s/^\)//; } else { - $$css =~ s/^($RE_STRING)//; + $$css =~ s/^($RE_STRING)//o; $uri = $1; $uri =~ s/^(?:'|")//; #" $uri =~ s/(?:'|")$//; #' @@ -630,7 +630,7 @@ my $css = shift; # test for the right content and return a list if found - return [] unless $$css =~ s/^\s*($RE_IDENT(?:\s*,\s*$RE_IDENT)*)//; + return [] unless $$css =~ s/^\s*($RE_IDENT(?:\s*,\s*$RE_IDENT)*)//o; return [map { $_ =~ s/^\s+//; $_ =~ s/\s+$//; $_; } split /,/, $1]; } #---------------------------------------------------------------------# @@ -749,7 +749,7 @@ } # element - elsif ($$css =~ s/^(?:($RE_IDENT|\*)?(\|))?($RE_IDENT|\*)//) { + elsif ($$css =~ s/^(?:($RE_IDENT|\*)?(\|))?($RE_IDENT|\*)//o) { # create element selector my ($ns,$lname); $lname = ($3 eq '*')?undef:$3; @@ -775,17 +775,17 @@ } # hash id - elsif ($$css =~ s/^#($RE_NAME)//) { + elsif ($$css =~ s/^#($RE_NAME)//o) { push @tokens, $sac->[_cf_]->create_id_condition($1); } # dot class - elsif ($$css =~ s/^\.($RE_IDENT)//) { + elsif ($$css =~ s/^\.($RE_IDENT)//o) { push @tokens, $sac->[_cf_]->create_class_condition(undef,$1); } # CSS3 pseudo-elements - elsif ($$css =~ s/^::($RE_IDENT)//) { + elsif ($$css =~ s/^::($RE_IDENT)//o) { push @tokens, $sac->[_sf_]->create_pseudo_element_selector(undef,$1); } @@ -799,7 +799,7 @@ $attr =~ s/\s*\]$//; # get the attr lname and ns - $attr =~ s/^(?:($RE_IDENT|\*)?(\|))?($RE_IDENT|\*)//; + $attr =~ s/^(?:($RE_IDENT|\*)?(\|))?($RE_IDENT|\*)//o; my ($ns,$lname); $lname = ($3 eq '*')?undef:$3; if (defined $2 and $2 eq '|') { @@ -864,7 +864,7 @@ # :pseudo() elsif ( - ($args,$$css,$func) = Text::Balanced::extract_bracketed($$css,q/()'"/,qr/:$RE_IDENT/) + ($args,$$css,$func) = Text::Balanced::extract_bracketed($$css,q/()'"/,qr/:$RE_IDENT/o) and length $func ) { @@ -910,7 +910,7 @@ } # :pseudo (not a function) - elsif ($$css =~ s/^\:($RE_IDENT)//) { + elsif ($$css =~ s/^\:($RE_IDENT)//o) { # root if (lc($1) eq 'root') { @@ -1153,7 +1153,7 @@ $$css =~ s/^\s*//; while (length $$css) { # the property - $$css =~ s/^(-?$RE_IDENT)\s*//; # includes the - prefix + $$css =~ s/^(-?$RE_IDENT)\s*//o; # includes the - prefix my $prop = $1; $sac->parse_comments($css); @@ -1247,21 +1247,21 @@ # lengths and assoc elsif ($$css =~ s/^((?:\+|-)?$RE_NUM) (em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%) - //xi) { + //xio) { $value = $1; $text = lc $2; $type = $DIM_MAP{$text}; } # dimension - elsif ($$css =~ s/^((?:\+|-)?$RE_NUM)($RE_IDENT)//) { + elsif ($$css =~ s/^((?:\+|-)?$RE_NUM)($RE_IDENT)//o) { $value = $1; $text = lc $2; $type = DIMENSION; } # number - elsif ($$css =~ s/^((?:\+|-)?$RE_NUM)//) { + elsif ($$css =~ s/^((?:\+|-)?$RE_NUM)//o) { $value = $1; $text = 'number'; if ($value =~ m/\./) { @@ -1273,7 +1273,7 @@ } # unicode range - elsif ($$css =~ s/^($RE_RANGE)//) { + elsif ($$css =~ s/^($RE_RANGE)//o) { $value = $1; $text = 'unicode-range'; $type = UNICODERANGE; @@ -1288,11 +1288,11 @@ # functions # elsif ( -# ($value,$$css,$text) = Text::Balanced::extract_bracketed($$css,q/()'"/,qr/$RE_IDENT/) +# ($value,$$css,$text) = Text::Balanced::extract_bracketed($$css,q/()'"/,qr/$RE_IDENT/o) # and # length $text # ) { - elsif ($$css =~ s/^($RE_IDENT)\(//) { + elsif ($$css =~ s/^($RE_IDENT)\(//o) { # cleanup the func and args # $text = lc $text; @@ -1313,14 +1313,14 @@ } # ident - elsif ($$css =~ s/^($RE_IDENT)//) { + elsif ($$css =~ s/^($RE_IDENT)//o) { $value = $1; $text = 'ident'; $type = IDENT; } # string - elsif ($$css =~ s/^($RE_STRING)//) { + elsif ($$css =~ s/^($RE_STRING)//o) { $value = $1; $value =~ s/^(?:"|')//; #" $value =~ s/(?:"|')$//; #"