diff options
author | Joseph Powers <jpowers27@cox.net> | 2011-02-15 07:44:21 -0800 |
---|---|---|
committer | Joseph Powers <jpowers27@cox.net> | 2011-02-15 07:44:21 -0800 |
commit | 6b0733a00b1b038fe20072984c87233c891660c8 (patch) | |
tree | 7487e5cb63a8eb5f88fef02c106fb4bb2c0e1fee /tools | |
parent | c83fae6da4ae1cc507af70fb6f04a8f53cf37fe5 (diff) |
Remove DECLARE_LIST( FSysSortList, FSysSort* )
Note: FSysSort is an int. So I just changed it to a vector< int >. This
should reduce the chance of a memory leek and also speed things up a little.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/inc/tools/fsys.hxx | 2 | ||||
-rw-r--r-- | tools/source/fsys/tdir.cxx | 107 |
2 files changed, 45 insertions, 64 deletions
diff --git a/tools/inc/tools/fsys.hxx b/tools/inc/tools/fsys.hxx index 0ea6c13b0863..a574dd104474 100644 --- a/tools/inc/tools/fsys.hxx +++ b/tools/inc/tools/fsys.hxx @@ -46,7 +46,6 @@ // -------------- class DirEntry; -class FSysSortList; class FileStatList; struct FileCopier_Impl; class SvFileStream; @@ -96,6 +95,7 @@ typedef int FSysSort; #define FSYS_SORT_KIND ((FSysSort) 256) #define FSYS_SORT_CREATOR ((FSysSort) 512) #define FSYS_SORT_END ((FSysSort)1024) +typedef ::std::vector< FSysSort > FSysSortList; // DirEntryFlag enum DirEntryFlag diff --git a/tools/source/fsys/tdir.cxx b/tools/source/fsys/tdir.cxx index 9011d4feea43..54e6c5ecf9fc 100644 --- a/tools/source/fsys/tdir.cxx +++ b/tools/source/fsys/tdir.cxx @@ -42,7 +42,6 @@ DBG_NAME( Dir ) -DECLARE_LIST( FSysSortList, FSysSort* ) DECLARE_LIST( FileStatList, FileStat* ) #define APPEND (USHORT) 65535 @@ -67,7 +66,7 @@ BOOL Dir::ImpInsertPointReached( const DirEntry& rNewEntry, if ( pLst->empty() ) return TRUE; - FSysSort nSort = *( pSortLst->GetObject( nSortIndex ) ); + FSysSort nSort = (*pSortLst)[ nSortIndex ]; FileStat *pOldStat = NULL; DirEntry *pCurLstObj = (*pLst)[ nCurPos ]; if ( pStatLst ) @@ -191,7 +190,7 @@ BOOL Dir::ImpInsertPointReached( const DirEntry& rNewEntry, default: /* Kann nicht sein */; } - if ( nSortIndex == ( pSortLst->Count() - 1 ) ) + if ( nSortIndex == ( pSortLst->size() - 1 ) ) return TRUE; else //Rekursion @@ -315,19 +314,22 @@ void Dir::Reset() } pStatLst->Clear(); delete pStatLst; + pStatLst = NULL; } // Verlangen die Sortierkriterien FileStat's? if ( pSortLst ) { - pSortLst->First(); - do - { - if ( *( pSortLst->GetCurObject() ) & - ( FSYS_SORT_KIND | FSYS_SORT_SIZE | - FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_ACCESSED ) ) + for ( size_t i = 0, n = pSortLst->size(); i < n; ++i ) { + if ( (*pSortLst)[ i ] + & ( FSYS_SORT_KIND | FSYS_SORT_SIZE | FSYS_SORT_CREATED + | FSYS_SORT_MODIFYED | FSYS_SORT_ACCESSED + ) + ) { pStatLst = new FileStatList(); - } while ( !pStatLst && pSortLst->Next() ); + break; + } + } } #ifndef BOOTSTRAP @@ -461,15 +463,7 @@ Dir::~Dir() // alle Sorts aus der Liste entfernen und deren Speicher freigeben if ( pSortLst ) { - FSysSort* pEntry = pSortLst->First(); - while (pEntry) - { - FSysSort* pNext = pSortLst->Next(); - delete pEntry; - pEntry = pNext; - } - pSortLst->Clear(); - + pSortLst->clear(); delete pSortLst; } @@ -500,18 +494,18 @@ Dir::~Dir() FSysError Dir::ImpSetSort( std::va_list pArgs, int nFirstSort ) { BOOL bLast; - FSysSort *pSort; + FSysSort aSort; FSysSortList *pNewSortLst = new FSysSortList; - *( pSort = new FSysSort ) = nFirstSort; + aSort = nFirstSort; do { // letztes Kriterium? - bLast = FSYS_SORT_END == (*pSort & FSYS_SORT_END); - *pSort &= ~FSYS_SORT_END; + bLast = FSYS_SORT_END == (aSort & FSYS_SORT_END); + aSort &= ~FSYS_SORT_END; - FSysSort nSort = *pSort & ~(USHORT)FSYS_SORT_ASCENDING - & ~(USHORT)FSYS_SORT_DESCENDING; + FSysSort nSort = aSort & ~(USHORT)FSYS_SORT_ASCENDING + & ~(USHORT)FSYS_SORT_DESCENDING; // g"utliges Sortierkriterium? if ( ( nSort == FSYS_SORT_NAME ) || @@ -522,49 +516,34 @@ FSysError Dir::ImpSetSort( std::va_list pArgs, int nFirstSort ) ( nSort == FSYS_SORT_ACCESSED ) || ( nSort == FSYS_SORT_KIND ) ) { - pNewSortLst->Insert( pSort, APPEND ); - *(pSort = new FSysSort) = va_arg( pArgs, FSysSort ); + pNewSortLst->push_back( aSort ); + aSort = va_arg( pArgs, FSysSort ); } else { // ungueltiger Sort oder FSYS_SORT_NONE - FSysSort* pEntry = pNewSortLst->First(); - while (pEntry) - { - FSysSort* pNext = pNewSortLst->Next(); - delete pEntry; - pEntry = pNext; - } - pNewSortLst->Clear(); + pNewSortLst->clear(); delete pNewSortLst; - if ( *pSort == FSYS_SORT_NONE ) + if ( aSort == FSYS_SORT_NONE ) { - delete pSort; - if ( pSortLst ) + if ( pSortLst ) { delete pSortLst; + pSortLst = NULL; + } return FSYS_ERR_OK; } else { - delete pSort; return FSYS_ERR_NOTSUPPORTED; } } } while ( !bLast ); va_end( pArgs ); - delete pSort; // JP:6.3.00 - delete the initial pointer //Enfernen der alten Sort-Elemente if ( pSortLst ) { - FSysSort* pEntry = pSortLst->First(); - while (pEntry) - { - FSysSort* pNext = pSortLst->Next(); - delete pEntry; - pEntry = pNext; - } - pSortLst->Clear(); + pSortLst->clear(); delete pSortLst; } pSortLst = pNewSortLst; @@ -575,17 +554,17 @@ FSysError Dir::ImpSetSort( std::va_list pArgs, int nFirstSort ) //ist der Aufruf von Update() die einfachste Moeglichkeit if ( !pStatLst && pSortLst ) { - pSortLst->First(); - do + for ( size_t i = 0, n = pSortLst->size(); i < n && !pStatLst; ++i ) { - if ( *(pSortLst->GetCurObject()) & - ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE | - FSYS_SORT_ACCESSED | FSYS_SORT_KIND ) ) - { + if ( (*pSortLst)[ i ] + & ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE + | FSYS_SORT_ACCESSED | FSYS_SORT_KIND + ) + ) { Update(); return FSYS_ERR_OK; } - } while ( !pStatLst && pSortLst->Next() ); + } } if ( pLst ) { //Keine DirEntry's, kein Sort. @@ -662,16 +641,18 @@ Dir& Dir::operator+=( const Dir& rDir ) //Verlangen die Sortierkriterien FileStat's? BOOL bStat = FALSE; if ( pSortLst ) { - pSortLst->First(); - do { - if ( *(pSortLst->GetCurObject()) & - ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE | - FSYS_SORT_ACCESSED | FSYS_SORT_KIND ) ) + for ( size_t i = 0, n = pSortLst->size(); i < n && !bStat; ++i ) { + if ( (*pSortLst)[ i ] + & ( FSYS_SORT_CREATED | FSYS_SORT_MODIFYED | FSYS_SORT_SIZE + | FSYS_SORT_ACCESSED | FSYS_SORT_KIND + ) + ) { bStat = TRUE; - } while ( !bStat && pSortLst->Next() ); + } + } } - FileStat * stat = NULL; - for ( USHORT nNr = 0; nNr < rDir.Count(); nNr++ ) + FileStat* stat = NULL; + for ( size_t nNr = 0; nNr < rDir.Count(); nNr++ ) { if ( bStat ) { |