Changeset 37866

Show
Ignore:
Timestamp:
06/27/10 15:14:34 (3 years ago)
Author:
walf443
Message:

プロフィリングをとりつつ最適化してみました

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTML-MobileJpCSS/trunk/lib/HTML/MobileJpCSS.pm

    r35772 r37866  
    5656    my ($self, $content) = @_; 
    5757    return $content if $self->{agent}->is_non_mobile; 
    58     return $content if $self->{agent}->is_ezweb && !(map { $self->{$_} } qw/inliner_ezweb css_file css/); 
     58    return $content if $self->{agent}->is_ezweb && !(grep { $self->{$_} } qw/inliner_ezweb css_file css/); 
    5959 
    6060    $content =~ s/(?:\r\n|\n)/\n/g; 
    6161 
    6262    my @css; 
    63     my @link = $content =~ /<link\s.*?rel="stylesheet".*?>/isg; 
     63    my @link = $content =~ /<link\s[^>]*?rel="stylesheet"[^>]*?>/isg; 
    6464    for (@link) { 
    6565        if (/href="(.+?)"/) { 
     
    6868        } 
    6969    } 
    70     $content =~ s/<link\s.*?rel="stylesheet".*?>\s*//isg if @link; 
     70    $content =~ s/<link\s[^>]*?rel="stylesheet"[^>]*?>\s*//isg if @link; 
    7171 
    7272    push @css, $self->_read($self->{css_file}) if $self->{css_file}; 
     
    7676    for my $css (@css) { 
    7777        for (keys %$css) { 
    78             if (/^a:(?:link|focus|visited)$/) { 
     78            if (/^a(?:\..+?)?:(?:link|focus|visited)$/) { 
    7979                $style->{pseudo}->{$_} = $style->{pseudo}->{$_} 
    8080                    ? { %{$style->{pseudo}->{$_}}, %{$css->{$_}} } 
     
    103103        my $css = bless $style->{pseudo}, 'CSS::Tiny'; 
    104104        my $pseudo = $self->{agent}->is_docomo ? "<![CDATA[\n".$css->write_string."]]>" : $css->write_string; 
    105         $content =~ s{<head>(.*)</head>}{<head>$1<style type="text/css">\n$pseudo</style></head>}is; 
     105        $content =~ s{</head>}{<style type="text/css">\n$pseudo</style></head>}is; 
    106106    } 
    107107 
     
    131131            $content = $self->_replace_style($content, $node, $props); 
    132132        } 
    133         $content =~ s/<([^<>]+?)\sclass="$class"([^<>]*?)>/<$1$2>/isg; 
     133        # 適用されたクラスをとり去る必要はないと思うな 
     134        # $content =~ s/<([^<>]+?)\sclass="$class"([^<>]*?)>/<$1$2>/isg; 
    134135    } 
    135136 
    136137    # istyle for DoCoMo 
    137     if ($self->{agent}->is_docomo) { 
    138         $content =~ s/(<input[^>]*?)(istyle="(\d)")([^>]*?>)/$1style="$IstyleDoCoMo{$3}"$4/isg; 
    139         $content =~ s/(<textarea[^>]*?)(istyle="(\d)")([^>]*?>)/$1style="$IstyleDoCoMo{$3}"$4/isg; 
     138    if ( ! $self->{no_istyle} ) { 
     139        if ($self->{agent}->is_docomo) { 
     140            $content =~ s/(<input[^>]*?)(istyle="(\d)")([^>]*?>)/$1style="$IstyleDoCoMo{$3}"$4/isg; 
     141            $content =~ s/(<textarea[^>]*?)(istyle="(\d)")([^>]*?>)/$1style="$IstyleDoCoMo{$3}"$4/isg; 
     142        } 
    140143    } 
    141144    return $content; 
     
    145148    my $self = shift; 
    146149    if ($self->{agent}) { 
    147         $self->{agent} = HTTP::MobileAgent->new($self->{agent}) unless (ref $self->{agent}) =~ /^HTTP::Mobile(Agent|Attribute)/; 
     150        if ( ! ref $self->{agent} ) { 
     151            $self->{agent} = HTTP::MobileAgent->new($self->{agent}); 
     152        } 
    148153    } 
    149154    else { 
     
    200205    my ($tag) = $node =~ /^<([^\s]+).*?>/is; 
    201206    my $replace = $node; 
    202     my $style; 
     207    my $style = ""; 
    203208    for (keys %$props) { 
    204209        $style .= $self->_filter($tag, $_, $props->{$_});