Add some basic prediction to CCDBNodeBranch::find

--HG--
branch : kaetemi-optimize
This commit is contained in:
kaetemi 2013-08-01 22:47:46 +02:00
parent d278a2ce23
commit 53bebec880
2 changed files with 29 additions and 0 deletions

View file

@ -21,6 +21,8 @@
#include "cdb.h"
#define NL_CDB_OPTIMIZE_PREDICT 1
namespace NLMISC{
/**
@ -247,6 +249,10 @@ protected:
/// called by clear
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" );
_NodesByName.push_back( node );
_Sorted = false;
#if NL_CDB_OPTIMIZE_PREDICT
_PredictNode = node;
#endif
}
} // attachChild //
@ -799,6 +802,18 @@ public:
//-----------------------------------------------
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)
{
_Sorted = true;
@ -812,7 +827,15 @@ ICDBNode *CCDBNodeBranch::find(const std::string &nodeName)
else
{
if (*(*it)->getName() == nodeName)
{
#if NL_CDB_OPTIMIZE_PREDICT
ICDBNode *node = *it;
_PredictNode = node;
return node;
#else
return *it;
#endif
}
else
return NULL;
}