diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2011-03-17 11:48:54 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2011-03-17 11:48:54 -0700 |
commit | eb9f5718d412022015bb65eb08c30785c79e79e6 (patch) | |
tree | be0b6a9de27965e39c44c5c8a88adf9caa13abf8 /src/cparse/cparse.ypp | |
parent | cda3f423c311fd30e8cc24e2de67d99baf352b2a (diff) | |
download | vyatta-cfg-eb9f5718d412022015bb65eb08c30785c79e79e6.tar.gz vyatta-cfg-eb9f5718d412022015bb65eb08c30785c79e79e6.zip |
add config path abstraction and high-level caching
* part of the config backend cleanup/optimization work.
* improves the performance of "load" (w/o commit) by ~55% and "show" by ~15%.
Diffstat (limited to 'src/cparse/cparse.ypp')
-rw-r--r-- | src/cparse/cparse.ypp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/cparse/cparse.ypp b/src/cparse/cparse.ypp index 24abbad..6b5d5c6 100644 --- a/src/cparse/cparse.ypp +++ b/src/cparse/cparse.ypp @@ -1,7 +1,6 @@ %{ #include <cstdio> #include <vector> -#include <map> #include <string> #include <cstore/cstore.hpp> @@ -39,25 +38,25 @@ static char *ncomment = NULL; static char *nname = NULL; static char *nval = NULL; -// XXX optimize: use unordered_map with non-vector -static map<vector<string>, CfgNode *> node_map; +typedef Cstore::MapT<Cpath, CfgNode *, CpathHash> NmapT; +static NmapT node_map; static Cstore *cstore_ = NULL; static CfgNode *cur_node = NULL; static CfgNode *cur_parent = NULL; static vector<CfgNode *> cur_path; -static vector<string> pcomps; +static Cpath pcomps; static vector<bool> pcomp_is_value; static void add_node() { - pcomps.push_back(nname); + pcomps.push(nname); CfgNode *onode = NULL; - map<vector<string>, CfgNode *>::iterator it = node_map.find(pcomps); + NmapT::iterator it = node_map.find(pcomps); if (it != node_map.end()) { onode = it->second; } - pcomps.pop_back(); + pcomps.pop(); if (onode) { if (nval) { if (onode->isMulti()) { @@ -92,9 +91,9 @@ add_node() mapped_node = p; } cur_parent->addChildNode(mapped_node); - pcomps.push_back(nname); + pcomps.push(nname); node_map[pcomps] = mapped_node; - pcomps.pop_back(); + pcomps.pop(); } } @@ -104,10 +103,10 @@ go_down() cur_path.push_back(cur_parent); cur_parent = cur_node; - pcomps.push_back(nname); + pcomps.push(nname); pcomp_is_value.push_back(false); if (nval) { - pcomps.push_back(nval); + pcomps.push(nval); pcomp_is_value.push_back(true); } } @@ -119,10 +118,10 @@ go_up() cur_path.pop_back(); if (pcomp_is_value.back()) { - pcomps.pop_back(); + pcomps.pop(); pcomp_is_value.pop_back(); } - pcomps.pop_back(); + pcomps.pop(); pcomp_is_value.pop_back(); } |