[Libreoffice-commits] .: tools/bootstrp tools/inc

Joseph Powers jpowers at kemper.freedesktop.org
Sat Jan 15 21:09:39 PST 2011


 tools/bootstrp/prj.cxx     |   62 +++++++++++++++++++++------------------------
 tools/inc/bootstrp/prj.hxx |    3 +-
 2 files changed, 32 insertions(+), 33 deletions(-)

New commits:
commit ae5a33575a05392b7f8f80dd4c63b9383483594d
Author: Joseph Powers <jpowers27 at cox.net>
Date:   Sat Jan 15 21:09:33 2011 -0800

    Convert SolarFileList from a vector to a list.
    
    It's actually a queue so files get processed from the front and added to
    the back.

diff --git a/tools/bootstrp/prj.cxx b/tools/bootstrp/prj.cxx
index 928dee6..c2bc3a4 100644
--- a/tools/bootstrp/prj.cxx
+++ b/tools/bootstrp/prj.cxx
@@ -584,24 +584,19 @@ void Star::Read( String &rFileName )
     aEntry = aEntry.GetPath().GetPath().GetPath();
     sSourceRoot = aEntry.GetFull();
 
-    // todo: change this to while( !aFileList.empty() )
-    for ( size_t i = 0, n = aFileList.size(); i < n; ++ i )
+    while ( !aFileList.empty() )
     {
-        StarFile *pFile = new StarFile( *aFileList[ i ] );
-        if ( pFile->Exists()) {
-            SimpleConfig aSolarConfig( *aFileList[ i ] );
+        StarFile *pFile = new StarFile( *aFileList.front() );
+        if ( pFile->Exists())
+        {
+            SimpleConfig aSolarConfig( *aFileList.front() );
             while (( aString = aSolarConfig.GetNext()) != "" )
                 InsertToken (( char * ) aString.GetBuffer());
         }
-        // todo: delete the pFile (it's not needed any more)
-        // todo: change the delete; to remove the 1st item in the list.
-        // what happens is new files may be added to the list by InsertToken()... thus, the list
-        // gets longer as things get processed. Thus, we need to remove things from the front as
-        // they get processed.
-        delete aFileList[ i ];
+        delete pFile;
+        delete aFileList.front();
+        aFileList.erase( aFileList.begin() );
     }
-    // todo: remove the clear(); if we left the loop above, then the list is empty
-    aFileList.clear();
     // resolve all dependencies recursive
     Expand_Impl();
 }
@@ -610,19 +605,21 @@ void Star::Read( String &rFileName )
 void Star::Read( SolarFileList *pSolarFiles )
 /*****************************************************************************/
 {
-    for ( size_t i = 0, n = pSolarFiles->size(); i < n; ++ i )
+    while ( !pSolarFiles->empty() )
     {
         ByteString aString;
 
-        StarFile *pFile = new StarFile( *(*pSolarFiles)[ i ] );
-        if ( pFile->Exists()) {
-            SimpleConfig aSolarConfig( *(*pSolarFiles)[ i ] );
+        StarFile *pFile = new StarFile( *pSolarFiles->front() );
+        if ( pFile->Exists())
+        {
+            SimpleConfig aSolarConfig( *pSolarFiles->front() );
             while (( aString = aSolarConfig.GetNext()) != "" )
                 InsertToken (( char * ) aString.GetBuffer());
         }
-        delete (*pSolarFiles)[ i ];
+        delete pFile;
+        delete pSolarFiles->front();
+        aFileList.erase( aFileList.begin() );
     }
-    pSolarFiles->clear();
     delete pSolarFiles;
 
     Expand_Impl();
@@ -654,10 +651,9 @@ void Star::InsertSolarList( String sProject )
     // inserts a new solarlist part of another project
     String sFileName( CreateFileName( sProject ));
 
-    for ( size_t i = 0; i < aFileList.size(); i++ ) {
-        if ( (*aFileList[ i ]) == sFileName )
+    for ( SolarFileList::iterator it = aFileList.begin(); it != aFileList.end(); ++it )
+        if ( *(*it) == sFileName )
             return;
-    }
 
     ByteString ssProject( sProject, RTL_TEXTENCODING_ASCII_US );
     if ( HasProject( ssProject ))
@@ -1107,17 +1103,18 @@ USHORT StarWriter::Read( String aFileName, BOOL bReadComments, USHORT nMode  )
     aEntry = aEntry.GetPath().GetPath().GetPath();
     sSourceRoot = aEntry.GetFull();
 
-    for ( size_t i = 0, n = aFileList.size(); i < n; ++i )
+    while ( !aFileList.empty() )
     {
-        StarFile *pFile = new StarFile( *aFileList[ i ] );
+        StarFile *pFile = new StarFile( *aFileList.front() );
         if ( pFile->Exists()) {
-            SimpleConfig aSolarConfig( *aFileList[ i ] );
+            SimpleConfig aSolarConfig( *aFileList.front() );
             while (( aString = aSolarConfig.GetCleanedNextLine( bReadComments )) != "" )
                 InsertTokenLine ( aString );
         }
-        delete aFileList[ i ];
+        delete pFile;
+        delete aFileList.front();
+        aFileList.erase( aFileList.begin() );
     }
-    aFileList.clear();
     // resolve all dependencies recursive
     Expand_Impl();
 
@@ -1133,18 +1130,19 @@ USHORT StarWriter::Read( SolarFileList *pSolarFiles, BOOL bReadComments )
     nStarMode = STAR_MODE_MULTIPLE_PARSE;
 
     // this ctor is used by StarBuilder to get the information for the whole workspace
-    for ( size_t i = 0, n = pSolarFiles->size(); i < n; ++i )
+    while ( !pSolarFiles->empty() )
     {
         ByteString aString;
-        StarFile *pFile = new StarFile(  *(*pSolarFiles)[ i ] );
+        StarFile *pFile = new StarFile( *pSolarFiles->front() );
         if ( pFile->Exists()) {
-            SimpleConfig aSolarConfig( *(*pSolarFiles)[ i ] );
+            SimpleConfig aSolarConfig( *pSolarFiles->front() );
             while (( aString = aSolarConfig.GetCleanedNextLine( bReadComments )) != "" )
                 InsertTokenLine ( aString );
         }
-        delete (*pSolarFiles)[ i ];
+        delete pFile;
+        delete pSolarFiles->front();
+        pSolarFiles->erase( pSolarFiles->begin() );
     }
-    pSolarFiles->clear();
     delete pSolarFiles;
 
     Expand_Impl();
diff --git a/tools/inc/bootstrp/prj.hxx b/tools/inc/bootstrp/prj.hxx
index ecd202a..56d9601 100644
--- a/tools/inc/bootstrp/prj.hxx
+++ b/tools/inc/bootstrp/prj.hxx
@@ -33,6 +33,7 @@
 #include <tools/stream.hxx>
 #include <osl/mutex.hxx>
 #include <vector>
+#include <list>
 
 #define OS_NONE				0x0000
 #define OS_WIN16			0x0001
@@ -295,7 +296,7 @@ public:
 typedef ::std::vector< Prj* > StarList;
 // todo: SolarFileList should be a linked list and not a vector.
 // also, the Read() functions need to be changed (see 1st read() in prj.cxx for notes)
-typedef ::std::vector< String* > SolarFileList;
+typedef ::std::list< String* > SolarFileList;
 
 class Star
 {


More information about the Libreoffice-commits mailing list