Skip to content

Make CSS-Prepare 6 times faster #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
53 changes: 31 additions & 22 deletions p5-CSS-Prepare/lib/CSS/Prepare.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,28 @@ sub new {
}

# check for ability to use plugins
my @parsers;
my @outputters;
map { push @parsers, "CSS::Prepare::Property::${_}::parse" }
@MODULES;
map { push @outputters, "CSS::Prepare::Property::${_}::output" }
@MODULES;
if ( $self->support_extended_syntax() ) {
eval "use Module::Pluggable require => 1;";
unless ($@) {
my @expanders;
foreach my $plugin ( $self->plugins() ) {
$self->{'has_plugins'} = 1;
push @expanders, "${plugin}::expand";
push @parsers, "${plugin}::parse";
push @outputters, "${plugin}::output";
}

$self->{'expanders'} = [@expanders];
}
}
$self->{'parsers'} = [@parsers];
$self->{'outputters'} = [@outputters];

return $self;
}
Expand Down Expand Up @@ -217,6 +231,18 @@ sub has_plugins {
my $self = shift;
return $self->{'has_plugins'};
}
sub parsers {
my $self = shift;
return @{$self->{'parsers'}};
}
sub outputters {
my $self = shift;
return @{$self->{'outputters'}};
}
sub expanders {
my $self = shift;
return @{$self->{'expanders'}};
}

my $elements_first = sub {
my $a_element = ( $a =~ m{^[a-z]}i );
Expand Down Expand Up @@ -467,16 +493,8 @@ sub output_properties {
}

my %properties;
my @outputters;

if ( $self->has_plugins() ) {
map { push @outputters, "${_}::output" }
$self->plugins();
}
map { push @outputters, "CSS::Prepare::Property::${_}::output" }
@MODULES;

foreach my $outputter ( @outputters ) {
foreach my $outputter ( $self->outputters ) {
my( @normal, @important );

eval {
Expand Down Expand Up @@ -1163,17 +1181,9 @@ sub parse_declaration {
my $has_hack = shift;
my $location = shift;
my %declaration = @_;

my @parsers;
map { push @parsers, "CSS::Prepare::Property::${_}::parse" }
@MODULES;
if ( $self->has_plugins() ) {
map { push @parsers, "${_}::parse" }
$self->plugins();
}


PARSER:
foreach my $module ( @parsers ) {
foreach my $module ( $self->parsers ) {
my $parsed_as;
my $errors;

Expand Down Expand Up @@ -1208,12 +1218,11 @@ sub expand_declarations {
my $value = $declaration->{'value'};

PLUGIN:
foreach my $plugin ( $self->plugins() ) {
foreach my $plugin ( $self->expanders ) {
no strict 'refs';

my $try_with = "${plugin}::expand";
my( $filtered, $new_rulesets, $new_chunks )
= &$try_with( $self, $property, $value, $selectors );
= &$plugin( $self, $property, $value, $selectors );

push @filtered, @{$filtered}
if defined $filtered;
Expand Down