File: speedup

package info (click to toggle)
libxml-twig-perl 1:3.32-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,988 kB
  • ctags: 806
  • sloc: perl: 17,411; xml: 202; makefile: 18
file content (55 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/perl 

# $Id: /xmltwig/trunk/speedup 31 2007-11-13T19:55:41.920709Z mrodrigu  $


$FIELD="parent|first_child|last_child|prev_sibling|next_sibling|pcdata|cdata|ent|data|target|cdata|pcdata|comment|flushed";
$FIELD2="parent|first_child|last_child|prev_sibling|next_sibling|pcdata|cdata|comment"; # _set_$field is inlined
$SET_FIELD="first_child|next_sibling|ent|data|target|comment|flushed";
# depending on the version of perl use either qr or ""
print STDERR "perl version is $]\n";

my $var= '(\$[a-z_]+(?:\[\d\])?)';

while( <>)
  {
    if( $] <= 5.005) { s{qr/(.*?)/}{"$1"} };
    if( $] < 5.006)       { if( m{# > perl 5.5}) { next; } }
    if( $] !~ m{^5.006})  { if( m{# = perl 5.6}) { next; } }
    
    if( $] < 5.006)  { s{^(\s*)no warnings;}    {$1# no warnings;}; }
    else             { s{^(\s*)# no warnings; } {$1no warnings;};   }

    s/$var->del_(twig_current|flushed)/delete $1\->{'$2'}/g;
    s/$var->set_(twig_current|flushed)/$1\->{'$2'}=1/g;

    s/$var->set_($SET_FIELD)\(([^)]*)\)/$1\->\{$2\}= $3/g;
    s/$var->($FIELD)\b(?!\()/$1\->\{$2\}/g;
    s/$var->_($FIELD2)\b(?!\()/$1\->\{$2\}/g;

    s/$var->(atts)\(([^)]*)\)/$1\->\{att\}/g;

    s/$var->append_(pcdata|cdata)\(([^)]*)\)/$1\->\{$2\}.= $3/g;

    s/(\$[a-z][a-z_]*(?:\[\d\])?)->gi/\$XML::Twig::index2gi\[$1\->{'gi'}\]/g;

    s/$var->id/$1\->{'att'}->{\$ID}/g;
    s/$var->att\(\s*([^)]+)\)/$1\->{'att'}->\{$2\}/g;

    s/(\$[a-z][a-z_]*(?:\[\d\])?)->is_pcdata/(exists $1\->{'pcdata'})/g; 
    s/(\$[a-z][a-z_]*(?:\[\d\])?)->is_cdata/(exists $1\->{'cdata'})/g; 
    s/$var->is_pi/(exists $1\->{'target'})/g; 
    s/$var->is_comment/(exists $1\->{'comment'})/g; 
    s/$var->is_ent/(exists $1\->{'ent'})/g; 
    s/(\$,a-z][a-z_]*(?:\[\d\])?)->is_text/((exists $1\->{'pcdata'}) || (exists $1\->{'cdata'}))/g; 

    s/$var->is_empty/($1\->{'empty'} || 0)/g;
    s/$var->set_empty(?:\(([^)]*)\))?(?!_)/"$1\->{empty}= " . ($2 || 1)/ge;
    s/$var->set_not_empty/delete $1\->{empty}/g;

    s/$var->_is_private/( (substr( \$XML::Twig::index2gi\[$1\->{'gi'}\], 0, 1) eq '#') && (substr( \$XML::Twig::index2gi\[$1\->{'gi'}\], 0, 9) ne '#default:') )/g;
    s/_is_private_name\(\s*$var\s*\)/( (substr( $1, 0, 1) eq '#') && (substr( $1, 0, 9) ne '#default:') )/g;

    print $_ ;
  }