#!/bin/perl # $Id: /xmltwig/trunk/speedup 3 2006-08-16T15:53:26.215012Z mrodrigu $ #use XML::Parser; $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 $] XML::Parser version is $XML::Parser::VERSION\n"; my $var= '(\$[a-z_]+(?:\[\d\])?)'; while( <>) { if( $] <= 5.005) { s{qr/(.*?)/}{"$1"} }; if( $] < 5.006) { if( m{# > 5.006}) { 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 $_ ; }