Add some basic prediction to CCDBNodeBranch::find

This commit is contained in:
kaetemi 2013-08-01 22:47:46 +02:00
parent 5caa7b7a91
commit 3d0e1ab03b
2 changed files with 29 additions and 0 deletions

View file

@ -21,6 +21,8 @@
#include "cdb.h" #include "cdb.h"
#define NL_CDB_OPTIMIZE_PREDICT 1
namespace NLMISC{ namespace NLMISC{
/** /**
@ -247,6 +249,10 @@ protected:
/// called by clear /// called by clear
void removeAllBranchObserver(); void removeAllBranchObserver();
#if NL_CDB_OPTIMIZE_PREDICT
CRefPtr<ICDBNode> _PredictNode;
#endif
}; };
} }

View file

@ -232,6 +232,9 @@ void CCDBNodeBranch::attachChild( ICDBNode * node, string nodeName )
//nldebug ( "CDB: Attaching node" ); //nldebug ( "CDB: Attaching node" );
_NodesByName.push_back( node ); _NodesByName.push_back( node );
_Sorted = false; _Sorted = false;
#if NL_CDB_OPTIMIZE_PREDICT
_PredictNode = node;
#endif
} }
} // attachChild // } // attachChild //
@ -799,6 +802,18 @@ public:
//----------------------------------------------- //-----------------------------------------------
ICDBNode *CCDBNodeBranch::find(const std::string &nodeName) ICDBNode *CCDBNodeBranch::find(const std::string &nodeName)
{ {
#if NL_CDB_OPTIMIZE_PREDICT
ICDBNode *predictNode = _PredictNode;
if (predictNode)
{
if (predictNode->getParent() == this
&& *predictNode->getName() == nodeName)
{
return predictNode;
}
}
#endif
if (!_Sorted) if (!_Sorted)
{ {
_Sorted = true; _Sorted = true;
@ -812,7 +827,15 @@ ICDBNode *CCDBNodeBranch::find(const std::string &nodeName)
else else
{ {
if (*(*it)->getName() == nodeName) if (*(*it)->getName() == nodeName)
{
#if NL_CDB_OPTIMIZE_PREDICT
ICDBNode *node = *it;
_PredictNode = node;
return node;
#else
return *it; return *it;
#endif
}
else else
return NULL; return NULL;
} }