Subject: | lvalue substr() is slow |
Hello,
I have profiled my application using S::ParseExcel, and it is shown that
lvalue substr() seems to make Spreadsheet::ParseExcel::Utility::ExcelFmt
a bottleneck.
The attached file simply replaces all the callings of lvalue substr() to
those of 4-args substr(). Could you please apply it to Utility.pm?
Regards,
--
Goro Fuji (GFUJI at CPAN.org)
Subject: | Utility.diff |
--- Spreadsheet-ParseExcel-0.44-orig/lib/Spreadsheet/ParseExcel/Utility.pm 2009-01-09 12:09:52.000000000 +0900
+++ Spreadsheet-ParseExcel-0.44/lib/Spreadsheet/ParseExcel/Utility.pm 2009-01-19 11:59:39.995710400 +0900
@@ -558,14 +558,14 @@
}
#print "REP:$sRep ",$rItem->[0], ":", $rItem->[1], ":" ,$rItem->[2], "\n";
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = $sRep;
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $sRep );
}
}
elsif ( ( $iFmtMode == 1 ) && ( $iData =~ /$sNUMEXP/ ) ) {
if ( $#aRep >= 0 ) {
while ( $aRep[$#aRep]->[0] eq ',' ) {
$iCmmCnt--;
- substr( $sFmtRes, $aRep[$#aRep]->[1], $aRep[$#aRep]->[2] ) = '';
+ substr( $sFmtRes, $aRep[$#aRep]->[1], $aRep[$#aRep]->[2], '' );
$iData /= 1000;
pop @aRep;
}
@@ -644,42 +644,42 @@
if ( $rItem->[0] =~
/([#0]*)([\.]?)([0#]*)([eE])([\+\-])([0#]+)/ )
{
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) =
- MakeE( $rItem->[0], $iData );
+ substr( $sFmtRes, $rItem->[1], $rItem->[2],
+ MakeE( $rItem->[0], $iData ) );
}
elsif ( $rItem->[0] =~ /\// ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) =
- MakeBun( $rItem->[0], $iData, $iInt );
+ substr( $sFmtRes, $rItem->[1], $rItem->[2],
+ MakeBun( $rItem->[0], $iData, $iInt ) );
}
elsif ( $rItem->[0] eq '.' ) {
$iLen--;
$iPPos = $iLen;
}
elsif ( $rItem->[0] eq '+' ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) =
- ( $iData > 0 ) ? '+' : ( ( $iData == 0 ) ? '+' : '-' );
+ substr( $sFmtRes, $rItem->[1], $rItem->[2],
+ ( $iData > 0 ) ? '+' : ( ( $iData == 0 ) ? '+' : '-' ) );
}
elsif ( $rItem->[0] eq '-' ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) =
- ( $iData > 0 ) ? '' : ( ( $iData == 0 ) ? '' : '-' );
+ substr( $sFmtRes, $rItem->[1], $rItem->[2],
+ ( $iData > 0 ) ? '' : ( ( $iData == 0 ) ? '' : '-' ) );
}
elsif ( $rItem->[0] eq '@' ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = $iData;
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $iData );
}
elsif ( $rItem->[0] eq '*' ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = ''; #REMOVE
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], '' ); #REMOVE
}
elsif (( $rItem->[0] eq "\xA2\xA4" )
or ( $rItem->[0] eq "\xA2\xA5" )
or ( $rItem->[0] eq "\x81\xA2" )
or ( $rItem->[0] eq "\x81\xA3" ) )
{
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = $rItem->[0];
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $rItem->[0] );
# ($iData > 0)? '': (($iData==0)? '':$rItem->[0]);
}
elsif ( ( $rItem->[0] eq '(' ) or ( $rItem->[0] eq ')' ) ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = $rItem->[0];
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $rItem->[0] );
# ($iData > 0)? '': (($iData==0)? '':$rItem->[0]);
}
@@ -707,8 +707,7 @@
else {
$sRep = '';
}
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) =
- "\x00" . $sRep;
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], "\x00" . $sRep );
}
}
$sRep = ( $iLen > 0 ) ? substr( $sNumRes, 0, $iLen ) : '';
@@ -721,11 +720,11 @@
for ( my $iIt = $#aRep ; $iIt >= 0 ; $iIt-- ) {
my $rItem = $aRep[$iIt];
if ( $rItem->[0] eq '@' ) {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = $iData;
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $iData );
$iAtMk++;
}
else {
- substr( $sFmtRes, $rItem->[1], $rItem->[2] ) = '';
+ substr( $sFmtRes, $rItem->[1], $rItem->[2], $iData );
}
}
$sFmtRes = $iData unless ($iAtMk);
@@ -742,7 +741,7 @@
if ( $sNum =~ /^([^\d]*)(\d\d\d\d+)(\.*.*)$/ ) {
my ( $sPre, $sObj, $sAft ) = ( $1, $2, $3 );
for ( my $i = length($sObj) - 3 ; $i > 0 ; $i -= 3 ) {
- substr( $sObj, $i, 0 ) = ',';
+ substr( $sObj, $i, 0, q{,} );
}
return $sPre . $sObj . $sAft;
}