Author: hdu
Date: Mon Jun 23 12:48:27 2014
New Revision: 1604786
URL: http://svn.apache.org/r1604786
Log:
#i125143# use bulk-copying instead of line-wise in helpex Export::CopyFile()
This simple change has been measured to speed up the helpex by almost 30%.
Modified:
openoffice/trunk/main/l10ntools/source/export2.cxx
Modified: openoffice/trunk/main/l10ntools/source/export2.cxx
URL:
http://svn.apache.org/viewvc/openoffice/trunk/main/l10ntools/source/export2.cxx?rev=1604786&r1=1604785&r2=1604786&view=diff
==============================================================================
--- openoffice/trunk/main/l10ntools/source/export2.cxx (original)
+++ openoffice/trunk/main/l10ntools/source/export2.cxx Mon Jun 23 12:48:27 2014
@@ -339,7 +339,7 @@ void Export::RemoveUTF8ByteOrderMarkerFr
bool Export::CopyFile( const ByteString& source , const ByteString& dest )
{
// cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer()
<< " )\n";
- const int BUFFERSIZE = 8192;
+ static const int BUFFERSIZE = 0x100000;
char buf[ BUFFERSIZE ];
FILE* IN_FILE = fopen( source.GetBuffer() , "r" );
@@ -356,28 +356,31 @@ bool Export::CopyFile( const ByteString&
fclose( IN_FILE );
return false;
}
-
- while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL )
+
+ bool bOk = true;
+ while( bOk )
{
- if( fputs( buf , OUT_FILE ) == EOF )
+ if( feof( IN_FILE ) )
+ break;
+ const size_t nBytesRead = fread( buf, 1, BUFFERSIZE, IN_FILE );
+ if( nBytesRead <= 0 )
+ {
+ if( ferror( IN_FILE ) )
+ {
+ cerr << "Export::CopyFile WARNING: Read problems " <<
dest.GetBuffer() << "\n";
+ bOk = false;
+ }
+ }
+ else if( fwrite( buf, 1, nBytesRead, OUT_FILE ) <= 0 )
{
cerr << "Export::CopyFile WARNING: Write problems " <<
source.GetBuffer() << "\n";
- fclose( IN_FILE );
- fclose( OUT_FILE );
- return false;
+ bOk = false;
}
}
- if( ferror( IN_FILE ) )
- {
- cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer()
<< "\n";
- fclose( IN_FILE );
- fclose( OUT_FILE );
- return false;
- }
fclose ( IN_FILE );
fclose ( OUT_FILE );
- return true;
+ return bOk;
}
/*****************************************************************************/