From 3d0e1ab03be873542212430cc06f8c7970a34987 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 1 Aug 2013 22:47:46 +0200 Subject: [PATCH] Add some basic prediction to CCDBNodeBranch::find --- code/nel/include/nel/misc/cdb_branch.h | 6 ++++++ code/nel/src/misc/cdb_branch.cpp | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/code/nel/include/nel/misc/cdb_branch.h b/code/nel/include/nel/misc/cdb_branch.h index 11adbac0d..f8a979499 100644 --- a/code/nel/include/nel/misc/cdb_branch.h +++ b/code/nel/include/nel/misc/cdb_branch.h @@ -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 _PredictNode; +#endif }; } diff --git a/code/nel/src/misc/cdb_branch.cpp b/code/nel/src/misc/cdb_branch.cpp index 998ea8cd3..627c1f38b 100644 --- a/code/nel/src/misc/cdb_branch.cpp +++ b/code/nel/src/misc/cdb_branch.cpp @@ -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; }