This commit is contained in:
Ingo Weinhold
2011-11-25 06:19:09 +01:00
parent b4a9359d84
commit 5deb28d6d2
@@ -4,13 +4,14 @@
*/ */
#include "NameIndex.h"
#include <TypeConstants.h> #include <TypeConstants.h>
#include <util/TwoKeyAVLTree.h> #include <util/TwoKeyAVLTree.h>
#include "DebugSupport.h" #include "DebugSupport.h"
#include "IndexImpl.h" #include "IndexImpl.h"
#include "NameIndex.h"
#include "Node.h" #include "Node.h"
#include "Volume.h" #include "Volume.h"
@@ -59,8 +60,7 @@ public:
// #pragma mark - NameIndexPrimaryKeyCompare // #pragma mark - NameIndexPrimaryKeyCompare
class NameIndexPrimaryKeyCompare class NameIndexPrimaryKeyCompare {
{
public: public:
inline int operator()(const NameIndexPrimaryKey &a, inline int operator()(const NameIndexPrimaryKey &a,
const NameIndexPrimaryKey &b) const const NameIndexPrimaryKey &b) const
@@ -171,7 +171,7 @@ NameIndex::NodeAdded(Node* node)
{ {
fEntries->Insert(node); fEntries->Insert(node);
// udpate live queries // update live queries
_UpdateLiveQueries(node, NULL, node->Name()); _UpdateLiveQueries(node, NULL, node->Name());
} }
@@ -181,7 +181,7 @@ NameIndex::NodeRemoved(Node* node)
{ {
fEntries->Remove(node, node); fEntries->Remove(node, node);
// udpate live queries // update live queries
_UpdateLiveQueries(node, node->Name(), NULL); _UpdateLiveQueries(node, node->Name(), NULL);
} }
@@ -317,28 +317,28 @@ NameIndexIterator::Next()
status_t status_t
NameIndexIterator::Suspend() NameIndexIterator::Suspend()
{ {
status_t error = !fSuspended ? B_OK : B_BAD_VALUE; if (fSuspended)
if (error == B_OK) { return B_BAD_VALUE;
if (fIterator.Current() != NULL) if (fIterator.Current() != NULL)
fIndex->GetVolume()->AddNodeListener(this, *fIterator.Current()); fIndex->GetVolume()->AddNodeListener(this, *fIterator.Current());
fSuspended = true; fSuspended = true;
} return B_OK;
return error;
} }
status_t status_t
NameIndexIterator::Resume() NameIndexIterator::Resume()
{ {
status_t error = fSuspended ? B_OK : B_BAD_VALUE; if (!fSuspended)
if (error == B_OK) { return B_BAD_VALUE;
if (fIterator.Current() != NULL) if (fIterator.Current() != NULL)
fIndex->GetVolume()->RemoveNodeListener(this); fIndex->GetVolume()->RemoveNodeListener(this);
fSuspended = false; fSuspended = false;
} return B_OK;
return error;
} }
@@ -350,21 +350,21 @@ NameIndexIterator::SetTo(NameIndex* index, const char* name, bool ignoreValue)
fIndex = index; fIndex = index;
fSuspended = false; fSuspended = false;
fIsNext = false; fIsNext = false;
if (fIndex != NULL) { if (fIndex == NULL)
return false;
if (ignoreValue) { if (ignoreValue) {
fIndex->fEntries->GetIterator(&fIterator); fIndex->fEntries->GetIterator(&fIterator);
return fIterator.Current() != NULL; return fIterator.Current() != NULL;
} }
return fIndex->fEntries->FindFirst(name, &fIterator); return fIndex->fEntries->FindFirst(name, &fIterator);
} }
return false;
}
void void
NameIndexIterator::NodeRemoved(Node* node) NameIndexIterator::NodeRemoved(Node* node)
{ {
Resume(); Resume();
fIsNext = Next(); fIsNext = Next() != NULL;
Suspend(); Suspend();
} }