speedup

filter: Statementstmt 98.3% 59 / 60 Branchbran 91.6% 11 / 12 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub n/a Podpod n/a totaltotal 94.8% 74 / 78 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« filter_for_5.005 ↑ Summary
1 #!/usr/bin/perl
2  
3 1 my $FIELD = join( '|', qw( parent first_child last_child prev_sibling next_sibling pcdata cdata ent data target cdata pcdata comment flushed));
4 1 my $PRIVATE = join( '|', qw( parent first_child last_child prev_sibling next_sibling pcdata cdata comment
5 extra_data_in_pcdata extra_data_before_end_tag
6 )
7 ); # _$private is inlined
8 1 my $FORMER = join( '|', qw( parent prev_sibling next_sibling)); # former_$former is inlined
9 1 my $SET_FIELD = join( '|', qw( first_child next_sibling ent data pctarget comment flushed));
10 1 my $SET_NOT_EMPTY= join( '|', qw( pcdata cdata comment)); # set the field
11  
12 # depending on the version of perl use either qr or ""
13 1 print STDERR "perl version is $]\n";
14  
15 1 my $var= '(\$[a-z_]+(?:\[\d\])?|\$t(?:wig)?->root|\$t(?:wig)?->twig_current|\$t(?:wig)?->\{\'?twig_root\'?\}|\$t(?:wig)?->\{\'?twig_current\'?\})';
16  
17 1 my $set_to = '(?:undef|\$\w+|\$\w+->\{\w+\}|\$\w+->\w+|\$\w+->\w+\([^)]+\))';
18 1 my $elt = '\$(?:elt|new_elt|child|cdata|ent|_?parent|twig_current|next_sibling|first_child|prev_sibling|last_child|ref|elt->_parent)';
19  
20  
21 1 my %gi2index=( '', 0, PCDATA => 1, CDATA => 2, PI => 3, COMMENT => 4, ENT => 5);
22  
23 1 (my $version= $])=~ s{\.}{}g;
24  
25 1 ▶while( <>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 14352 1 14353
26 {
27 14352 ▶ if( $] <= 5.005) { s{qr/(.*?)/}{"$1"} };
Branch: 1 branch
BranchTrueFalseTotal
if ($] <= "5.005") 0 14352 14352
28  
29 # when finding a comment # perl > 5.8 or # perl < 5.5, process accordingly
30 14352 ▶ if( my( $op, $v, $mv)= m{#\s*(>|<|>=|<=)\s*perl\s*5\.(\d+)(?:\.(\d+))?\s*})
Branch: 1 branch
BranchTrueFalseTotal
if (() = /#\s*(>|<|>=|<=)\s*perl\s*5\.(\d+)(?:\.(\d+))?\s*/) 25 14327 14352
31 25 ▶ { $v= sprintf( "5%03d%03d", $v, $mv || 0);
Condition50%1/2
$mv || 0
l!l
025
MC/DC0%0/1
$mv || 0
$mv
Truth table50%1/2
A
A= $mv
Aresult
11
00
32 25 my $comp= "$version $op $v";
33 25 ▶ if( ! eval $comp) { print "#$_"; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (not eval $comp) { } 4 21 25
34 21 ▶ else { s{#[^#]*\n}{\n} if m{^=encoding}; }
Branch: 1 branch
BranchTrueFalseTotal
if /^=encoding/ 1 20 21
35 }
36  
37
38 14348 ▶ if( /=/)
Branch: 1 branch
BranchTrueFalseTotal
if (/=/) 3961 10387 14348
39 3961 { s/$var->_children/do { my \$elt= $1; my \@children=(); my \$child= \$elt->_first_child; while( \$child) { push \@children, \$child; \$child= \$child->_next_sibling; } \@children; }/; }
40  
41 14348 s/$var->set_gi\(\s*(PCDATA|CDATA|PI|COMMENT|ENT)\s*\)/$1\->{gi}= $gi2index{$2}/;
42  
43 14348 s/$var->del_(twig_current)/delete $1\->{'$2'}/g;
44 14348 s/$var->set_(twig_current)/$1\->{'$2'}=1/g;
45 14348 s/$var->_del_(flushed)/delete $1\->{'$2'}/g;
46 14348 s/$var->_set_(flushed)/$1\->{'$2'}=1/g;
47 14348 s/$var->_(flushed)/$1\->{'$2'}/g;
48  
49 14348 s/$var->set_($SET_FIELD)\(([^)]*)\)/$1\->\{$2\}= $3/g;
50 14348 s/$var->($FIELD)\b(?!\()/$1\->\{$2\}/g;
51 #s/$var->_($PRIVATE)\b(?!\()/$1\->\{$2\}/g;
52 14348 s/$var->_($PRIVATE)\b(\s*\(\s*\))?(?!\s*\()/$1\->\{$2\}/g;
53  
54 14348 s{($elt)->former_($FORMER)}{($1\->{former} && $1\->{former}\->{$2})}g;
55  
56 14348 s{($elt)->set_(parent|prev_sibling)\(\s*($set_to)\s*\)}{$1\->\{$2\}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->\{$2\});} }g;
57 14348 s{($elt)->set_(first_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->\{$2\}=$3; }g;
58 14348 s{($elt)->set_(next_sibling)\(\s*($set_to)\s*\)}{ $1\->\{$2\}=$3; }g;
59 14348 s{($elt)->set_(last_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->\{$2\}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->\{$2\});} }g;
60  
61 14348 s/$var->atts/$1\->{att}/g;
62  
63 14348 s/$var->append_(pcdata|cdata)\(([^)]*)\)/$1\->\{$2\}.= $3/g;
64 14348 s/$var->set_($SET_NOT_EMPTY)\(([^)]*)\)/$1\->\{$2\}= (delete $1->\{empty\} || 1) && $3/g;
65 14348 s/$var->_set_($SET_NOT_EMPTY)\s*\(([^)]*)\)/$1\->{$2}= $3/g;
66  
67 14348 s/(\$[a-z][a-z_]*(?:\[\d\])?)->gi/\$XML::Twig::index2gi\[$1\->{'gi'}\]/g;
68  
69 14348 s/$var->id/$1\->{'att'}->{\$ID}/g;
70 14348 s/$var->att\(\s*([^)]+)\)/$1\->{'att'}->\{$2\}/g;
71  
72 14348 s/(\$[a-z][a-z_]*(?:\[\d\])?)->is_pcdata/(exists $1\->{'pcdata'})/g;
73 14348 s/(\$[a-z][a-z_]*(?:\[\d\])?)->is_cdata/(exists $1\->{'cdata'})/g;
74 14348 s/$var->is_pi/(exists $1\->{'target'})/g;
75 14348 s/$var->is_comment/(exists $1\->{'comment'})/g;
76 14348 s/$var->is_ent/(exists $1\->{'ent'})/g;
77 14348 s/(\$,a-z][a-z_]*(?:\[\d\])?)->is_text/((exists $1\->{'pcdata'}) || (exists $1\->{'cdata'}))/g;
78  
79 14348 s/$var->is_empty/$1\->{'empty'}/g;
80 14348 ▶ s/$var->set_empty(?:\(([^)]*)\))?(?!_)/"$1\->{empty}= " . ($2 || 1)/ge;
Condition100%2/2
$2 || 1
l!l
71
MC/DC100%1/1
$2 || 1
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
81 14348 s/$var->set_not_empty/delete $1\->{empty}/g;
82 #s/$var->set_not_empty/delete $1\->{empty}/g;
83  
84 14348 s/$var->_is_private/( (substr( \$XML::Twig::index2gi\[$1\->{'gi'}\], 0, 1) eq '#') && (substr( \$XML::Twig::index2gi\[$1\->{'gi'}\], 0, 9) ne '#default:') )/g;
85 #s/_is_private_name\(\s*$var\s*\)/( (substr( $1, 0, 1) eq '#') && (substr( $1, 0, 9) ne '#default:') )/g;
86 14348 s/_is_private_name\(\s*$var\s*\)/( $1=~ m{^#(?!default:)} )/g;
87  
88 14348 s{_is_fh\(\s*$var\)}{isa( $1, 'GLOB') || isa( $1, 'IO::Scalar')}g;
89  
90 # $var->set_gi( $gi): set the gi, but if it doesn't exist, call the original set_gi
91 14348 s/$var->set_gi\s*\(\s*([^)]*)\s*\)/$1\->{gi}=\$XML::Twig::gi2index{$2} or $1->set_gi( $2)/g;
92  
93 14348 s/$var->xml_string/$1->sprint( 1)/g;
94  
95  
96 14348 print $_ ;
97 }
98  
« filter_for_5.005 ↑ Summary