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"
@@ -24,8 +25,8 @@ public:
: :
entry(entry), entry(entry),
name(name ? name : entry->Name()) name(name ? name : entry->Name())
{ {
} }
NameIndexPrimaryKey(const char* name) NameIndexPrimaryKey(const char* name)
: :
@@ -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)
fIndex->GetVolume()->AddNodeListener(this, *fIterator.Current());
fSuspended = true; if (fIterator.Current() != NULL)
} fIndex->GetVolume()->AddNodeListener(this, *fIterator.Current());
return error;
fSuspended = true;
return B_OK;
} }
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)
fIndex->GetVolume()->RemoveNodeListener(this);
fSuspended = false; if (fIterator.Current() != NULL)
} fIndex->GetVolume()->RemoveNodeListener(this);
return error;
fSuspended = false;
return B_OK;
} }
@@ -350,14 +350,14 @@ 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)
if (ignoreValue) { return false;
fIndex->fEntries->GetIterator(&fIterator);
return fIterator.Current() != NULL; if (ignoreValue) {
} fIndex->fEntries->GetIterator(&fIterator);
return fIndex->fEntries->FindFirst(name, &fIterator); return fIterator.Current() != NULL;
} }
return false; return fIndex->fEntries->FindFirst(name, &fIterator);
} }
@@ -365,6 +365,6 @@ void
NameIndexIterator::NodeRemoved(Node* node) NameIndexIterator::NodeRemoved(Node* node)
{ {
Resume(); Resume();
fIsNext = Next(); fIsNext = Next() != NULL;
Suspend(); Suspend();
} }