You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by hd...@apache.org on 2014/07/07 10:45:10 UTC

svn commit: r1608366 - in /openoffice/branches/AOO410: ./ main/ main/l10ntools/source/export2.cxx

Author: hdu
Date: Mon Jul  7 08:45:10 2014
New Revision: 1608366

URL: http://svn.apache.org/r1608366
Log:
#i125143# speedup helpex by using bulk-copy instead of doing it line-wise

Merged from trunk revision 1604786 and revision 1605044

Modified:
    openoffice/branches/AOO410/   (props changed)
    openoffice/branches/AOO410/main/   (props changed)
    openoffice/branches/AOO410/main/l10ntools/source/export2.cxx

Propchange: openoffice/branches/AOO410/
------------------------------------------------------------------------------
  Merged /openoffice/trunk:r1604786,1605044

Propchange: openoffice/branches/AOO410/main/
------------------------------------------------------------------------------
  Merged /openoffice/trunk/main:r1604786,1605044

Modified: openoffice/branches/AOO410/main/l10ntools/source/export2.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/AOO410/main/l10ntools/source/export2.cxx?rev=1608366&r1=1608365&r2=1608366&view=diff
==============================================================================
--- openoffice/branches/AOO410/main/l10ntools/source/export2.cxx (original)
+++ openoffice/branches/AOO410/main/l10ntools/source/export2.cxx Mon Jul  7 08:45:10 2014
@@ -36,6 +36,7 @@
 #include <tools/urlobj.hxx>
 #include <time.h>
 #include <stdlib.h>
+#include <boost/shared_ptr.hpp>
 
 using namespace std;
 //
@@ -339,9 +340,6 @@ void Export::RemoveUTF8ByteOrderMarkerFr
 bool Export::CopyFile( const ByteString& source , const ByteString& dest )
 {
 //    cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n";
-    const int BUFFERSIZE    = 8192;
-    char buf[ BUFFERSIZE ];
-
     FILE* IN_FILE = fopen( source.GetBuffer() , "r" );
     if( IN_FILE == NULL )
     {
@@ -356,28 +354,35 @@ bool Export::CopyFile( const ByteString&
         fclose( IN_FILE );
         return false;
     }
-   
-    while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL )
+
+    static const int BUFFERSIZE = 0x100000;
+    boost::shared_ptr<char> aScopedBuffer( new char[BUFFERSIZE] );
+    char* buf = aScopedBuffer.get();
+
+    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;
 }
 
 /*****************************************************************************/