Tracker: style fixes to EntryIterator

This commit is contained in:
John Scipione
2014-06-20 21:01:41 -04:00
parent a3c479b7e8
commit e4d63b6d50
2 changed files with 40 additions and 24 deletions
+33 -18
View File
@@ -32,8 +32,10 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#include <Debug.h> #include <Debug.h>
#include <Entry.h> #include <Entry.h>
#include <ObjectList.h>
#include <Path.h> #include <Path.h>
#include <new> #include <new>
@@ -41,7 +43,9 @@ All rights reserved.
#include "EntryIterator.h" #include "EntryIterator.h"
#include "NodeWalker.h" #include "NodeWalker.h"
#include "ObjectList.h"
// #pragma mark - TWalkerWrapper
TWalkerWrapper::TWalkerWrapper(BTrackerPrivate::TWalker* walker) TWalkerWrapper::TWalkerWrapper(BTrackerPrivate::TWalker* walker)
@@ -69,6 +73,7 @@ status_t
TWalkerWrapper::GetNextEntry(BEntry* entry, bool traverse) TWalkerWrapper::GetNextEntry(BEntry* entry, bool traverse)
{ {
fStatus = fWalker->GetNextEntry(entry, traverse); fStatus = fWalker->GetNextEntry(entry, traverse);
return fStatus; return fStatus;
} }
@@ -77,6 +82,7 @@ status_t
TWalkerWrapper::GetNextRef(entry_ref* ref) TWalkerWrapper::GetNextRef(entry_ref* ref)
{ {
fStatus = fWalker->GetNextRef(ref); fStatus = fWalker->GetNextRef(ref);
return fStatus; return fStatus;
} }
@@ -87,6 +93,7 @@ TWalkerWrapper::GetNextDirents(struct dirent* buffer, size_t length,
{ {
int32 result = fWalker->GetNextDirents(buffer, length, count); int32 result = fWalker->GetNextDirents(buffer, length, count);
fStatus = result < B_OK ? result : (result ? B_OK : B_ENTRY_NOT_FOUND); fStatus = result < B_OK ? result : (result ? B_OK : B_ENTRY_NOT_FOUND);
return result; return result;
} }
@@ -105,11 +112,12 @@ TWalkerWrapper::CountEntries()
} }
// #pragma mark - // #pragma mark - EntryListBase
EntryListBase::EntryListBase() EntryListBase::EntryListBase()
: fStatus(B_OK) :
fStatus(B_OK)
{ {
} }
@@ -128,7 +136,7 @@ EntryListBase::Next(dirent* ent)
} }
// #pragma mark - // #pragma mark - CachedEntryIterator
CachedEntryIterator::CachedEntryIterator(BEntryList* iterator, CachedEntryIterator::CachedEntryIterator(BEntryList* iterator,
@@ -163,10 +171,11 @@ CachedEntryIterator::GetNextEntry(BEntry* result, bool traverse)
ASSERT(!fDirentBuffer); ASSERT(!fDirentBuffer);
ASSERT(!fEntryRefBuffer); ASSERT(!fEntryRefBuffer);
if (!fEntryBuffer) { if (fEntryBuffer == NULL) {
fEntryBuffer = new BEntry [fCacheSize]; fEntryBuffer = new BEntry [fCacheSize];
ASSERT(fIndex == 0 && fNumEntries == 0); ASSERT(fIndex == 0 && fNumEntries == 0);
} }
if (fIndex >= fNumEntries) { if (fIndex >= fNumEntries) {
// fill up the buffer or stop if error; keep error around // fill up the buffer or stop if error; keep error around
// and return it when appropriate // and return it when appropriate
@@ -179,6 +188,7 @@ CachedEntryIterator::GetNextEntry(BEntry* result, bool traverse)
} }
fIndex = 0; fIndex = 0;
} }
*result = fEntryBuffer[fIndex++]; *result = fEntryBuffer[fIndex++];
if (fIndex > fNumEntries) { if (fIndex > fNumEntries) {
// we are at the end of the cache we loaded up, time to return // we are at the end of the cache we loaded up, time to return
@@ -193,10 +203,10 @@ CachedEntryIterator::GetNextEntry(BEntry* result, bool traverse)
status_t status_t
CachedEntryIterator::GetNextRef(entry_ref* ref) CachedEntryIterator::GetNextRef(entry_ref* ref)
{ {
ASSERT(!fDirentBuffer); ASSERT(fDirentBuffer == NULL);
ASSERT(!fEntryBuffer); ASSERT(fEntryBuffer == NULL);
if (!fEntryRefBuffer) { if (fEntryRefBuffer == NULL) {
fEntryRefBuffer = new entry_ref[fCacheSize]; fEntryRefBuffer = new entry_ref[fCacheSize];
ASSERT(fIndex == 0 && fNumEntries == 0); ASSERT(fIndex == 0 && fNumEntries == 0);
} }
@@ -212,11 +222,13 @@ CachedEntryIterator::GetNextRef(entry_ref* ref)
} }
fIndex = 0; fIndex = 0;
} }
*ref = fEntryRefBuffer[fIndex++]; *ref = fEntryRefBuffer[fIndex++];
if (fIndex > fNumEntries) if (fIndex > fNumEntries) {
// we are at the end of the cache we loaded up, time to return // we are at the end of the cache we loaded up, time to return
// an error, if we had one // an error, if we had one
return fStatus; return fStatus;
}
return B_OK; return B_OK;
} }
@@ -227,6 +239,7 @@ CachedEntryIterator::_CompareInodes(const dirent* ent1, const dirent* ent2)
{ {
if (ent1->d_ino < ent2->d_ino) if (ent1->d_ino < ent2->d_ino)
return -1; return -1;
if (ent1->d_ino == ent2->d_ino) if (ent1->d_ino == ent2->d_ino)
return 0; return 0;
@@ -238,14 +251,14 @@ int32
CachedEntryIterator::GetNextDirents(struct dirent* ent, size_t size, CachedEntryIterator::GetNextDirents(struct dirent* ent, size_t size,
int32 count) int32 count)
{ {
ASSERT(!fEntryRefBuffer); ASSERT(fEntryRefBuffer == NULL);
if (!fDirentBuffer) { if (fDirentBuffer == NULL) {
fDirentBuffer = (dirent*)malloc(kDirentBufferSize); fDirentBuffer = (dirent*)malloc(kDirentBufferSize);
ASSERT(fIndex == 0 && fNumEntries == 0); ASSERT(fIndex == 0 && fNumEntries == 0);
ASSERT(size > sizeof(dirent) + B_FILE_NAME_LENGTH); ASSERT(size > sizeof(dirent) + B_FILE_NAME_LENGTH);
} }
if (!count) if (count == 0)
return 0; return 0;
if (fIndex >= fNumEntries) { if (fIndex >= fNumEntries) {
@@ -346,11 +359,12 @@ CachedEntryIterator::SetTo(BEntryList* iterator)
} }
// #pragma mark - // #pragma mark - CachedDirectoryEntryList
CachedDirectoryEntryList::CachedDirectoryEntryList(const BDirectory &dir) CachedDirectoryEntryList::CachedDirectoryEntryList(const BDirectory &dir)
: CachedEntryIterator(0, 40, true), :
CachedEntryIterator(0, 40, true),
fDir(dir) fDir(dir)
{ {
fStatus = fDir.InitCheck(); fStatus = fDir.InitCheck();
@@ -363,7 +377,7 @@ CachedDirectoryEntryList::~CachedDirectoryEntryList()
} }
// #pragma mark - // #pragma mark - DirectoryEntryList
DirectoryEntryList::DirectoryEntryList(const BDirectory &dir) DirectoryEntryList::DirectoryEntryList(const BDirectory &dir)
@@ -414,7 +428,7 @@ DirectoryEntryList::CountEntries()
} }
// #pragma mark - // #pragma mark - EntryIteratorList
EntryIteratorList::EntryIteratorList() EntryIteratorList::EntryIteratorList()
@@ -535,11 +549,12 @@ EntryIteratorList::CountEntries()
} }
// #pragma mark - // #pragma mark - CachedEntryIteratorList
CachedEntryIteratorList::CachedEntryIteratorList(bool sortInodes) CachedEntryIteratorList::CachedEntryIteratorList(bool sortInodes)
: CachedEntryIterator(NULL, 10, sortInodes) :
CachedEntryIterator(NULL, 10, sortInodes)
{ {
fStatus = B_OK; fStatus = B_OK;
SetTo(&fIteratorList); SetTo(&fIteratorList);
+6 -5
View File
@@ -31,19 +31,19 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders. names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#ifndef __ENTRY_ITERATOR__
#define __ENTRY_ITERATOR__
// A lot of the code in here wouldn't be needed if the destructor // A lot of the code in here wouldn't be needed if the destructor
// for BEntryList was virtual // for BEntryList was virtual
// TODO: get rid of all BEntryList API's in here, replace them with // TODO: get rid of all BEntryList API's in here, replace them with
// EntryListBase ones // EntryListBase ones
#ifndef _ENTRY_ITERATOR_H
#define _ENTRY_ITERATOR_H
#include <Directory.h> #include <Directory.h>
#include "ObjectList.h" #include <ObjectList.h>
#include "NodeWalker.h" #include "NodeWalker.h"
@@ -207,4 +207,5 @@ protected:
using namespace BPrivate; using namespace BPrivate;
#endif
#endif // _ENTRY_ITERATOR_H