Remove PropertyMap from XMLNode class

It appears that there is no performance benefit from storing properties in a
map for faster lookup or it is counteracted by the penalty of storing and
maintaining the additional data structure.

Timing results before changes with an optimized build:

XMLTest::testPerfMediumXMLDocumentTiming
   Create : Count: 10 Min: 41293 Max: 63746 Total: 564448 Avg: 56444 (56 msecs)
   Write : Count: 10 Min: 42932 Max: 49221 Total: 453955 Avg: 45395 (45 msecs)
   Read : Count: 10 Min: 80160 Max: 84678 Total: 824506 Avg: 82450 (82 msecs)

XMLTest::testPerfLargeXMLDocumentTiming
   Create : Count: 10 Min: 228759 Max: 420236 Total: 3587597 Avg: 358759 (358 msecs)
   Write : Count: 10 Min: 307095 Max: 348767 Total: 3205704 Avg: 320570 (320 msecs)
   Read : Count: 10 Min: 572400 Max: 657219 Total: 5959630 Avg: 595963 (595 msecs)

Perf results after changes:

XMLTest::testPerfMediumXMLDocumentTiming
   Create : Count: 10 Min: 30610 Max: 42656 Total: 376672 Avg: 37667 (37 msecs)
   Write : Count: 10 Min: 42804 Max: 54277 Total: 460455 Avg: 46045 (46 msecs)
   Read : Count: 10 Min: 70364 Max: 85484 Total: 750909 Avg: 75090 (75 msecs)

XMLTest::testPerfLargeXMLDocumentTiming
   Create : Count: 10 Min: 164360 Max: 356995 Total: 3064482 Avg: 306448 (306 msecs)
   Write : Count: 10 Min: 308655 Max: 372953 Total: 3226707 Avg: 322670 (322 msecs)
   Read : Count: 10 Min: 517243 Max: 541839 Total: 5289950 Avg: 528995 (528 msecs)
This commit is contained in:
Tim Mayberry 2016-09-23 22:56:36 +10:00
parent 97752e6a51
commit e84fbfe6e5
2 changed files with 58 additions and 48 deletions

View file

@ -29,7 +29,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <cstdio> #include <cstdio>
#include <cstdarg> #include <cstdarg>
@ -50,7 +49,6 @@ typedef XMLNodeList::const_iterator XMLNodeConstIterator;
typedef std::vector<XMLProperty*> XMLPropertyList; typedef std::vector<XMLProperty*> XMLPropertyList;
typedef XMLPropertyList::iterator XMLPropertyIterator; typedef XMLPropertyList::iterator XMLPropertyIterator;
typedef XMLPropertyList::const_iterator XMLPropertyConstIterator; typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
typedef std::map<std::string, XMLProperty*> XMLPropertyMap;
class LIBPBD_API XMLTree { class LIBPBD_API XMLTree {
public: public:
@ -149,7 +147,6 @@ private:
std::string _content; std::string _content;
XMLNodeList _children; XMLNodeList _children;
XMLPropertyList _proplist; XMLPropertyList _proplist;
XMLPropertyMap _propmap;
mutable XMLNodeList _selected_children; mutable XMLNodeList _selected_children;
void clear_lists (); void clear_lists ();

View file

@ -245,7 +245,6 @@ XMLNode::clear_lists ()
XMLPropertyIterator curprop; XMLPropertyIterator curprop;
_selected_children.clear (); _selected_children.clear ();
_propmap.clear ();
for (curchild = _children.begin(); curchild != _children.end(); ++curchild) { for (curchild = _children.begin(); curchild != _children.end(); ++curchild) {
delete *curchild; delete *curchild;
@ -469,87 +468,99 @@ XMLNode::add_content(const string& c)
} }
XMLProperty const * XMLProperty const *
XMLNode::property(const char* n) const XMLNode::property(const char* name) const
{ {
string ns(n); XMLPropertyConstIterator iter = _proplist.begin();
map<string,XMLProperty*>::const_iterator iter;
if ((iter = _propmap.find(ns)) != _propmap.end()) { while (iter != _proplist.end()) {
return iter->second; if ((*iter)->name() == name) {
return *iter;
}
++iter;
} }
return 0; return 0;
} }
XMLProperty const * XMLProperty const *
XMLNode::property(const string& ns) const XMLNode::property(const string& name) const
{ {
map<string,XMLProperty*>::const_iterator iter; XMLPropertyConstIterator iter = _proplist.begin();
if ((iter = _propmap.find(ns)) != _propmap.end()) { while (iter != _proplist.end()) {
return iter->second; if ((*iter)->name() == name) {
return *iter;
}
++iter;
} }
return 0; return 0;
} }
XMLProperty * XMLProperty *
XMLNode::property(const char* n) XMLNode::property(const char* name)
{ {
string ns(n); XMLPropertyIterator iter = _proplist.begin();
map<string,XMLProperty*>::iterator iter;
if ((iter = _propmap.find(ns)) != _propmap.end()) { while (iter != _proplist.end()) {
return iter->second; if ((*iter)->name() == name) {
return *iter;
}
++iter;
} }
return 0; return 0;
} }
XMLProperty * XMLProperty *
XMLNode::property(const string& ns) XMLNode::property(const string& name)
{ {
map<string,XMLProperty*>::iterator iter; XMLPropertyIterator iter = _proplist.begin();
if ((iter = _propmap.find(ns)) != _propmap.end()) { while (iter != _proplist.end()) {
return iter->second; if ((*iter)->name() == name) {
return *iter;
}
++iter;
} }
return 0; return 0;
} }
bool bool
XMLNode::has_property_with_value (const string& key, const string& value) const XMLNode::has_property_with_value (const string& name, const string& value) const
{ {
map<string,XMLProperty*>::const_iterator iter = _propmap.find(key); XMLPropertyConstIterator iter = _proplist.begin();
if (iter != _propmap.end()) {
const XMLProperty* p = (iter->second); while (iter != _proplist.end()) {
return (p && p->value() == value); if ((*iter)->name() == name && (*iter)->value() == value) {
return true;
}
++iter;
} }
return false; return false;
} }
XMLProperty* XMLProperty*
XMLNode::add_property(const char* n, const string& v) XMLNode::add_property(const char* name, const string& value)
{ {
string ns(n); XMLPropertyIterator iter = _proplist.begin();
map<string,XMLProperty*>::iterator iter;
if ((iter = _propmap.find(ns)) != _propmap.end()) { while (iter != _proplist.end()) {
iter->second->set_value (v); if ((*iter)->name() == name) {
return iter->second; (*iter)->set_value (value);
return *iter;
}
++iter;
} }
XMLProperty* tmp = new XMLProperty(ns, v); XMLProperty* new_property = new XMLProperty(name, value);
if (!tmp) { if (!new_property) {
return 0; return 0;
} }
_propmap[tmp->name()] = tmp; _proplist.insert(_proplist.end(), new_property);
_proplist.insert(_proplist.end(), tmp);
return tmp; return new_property;
} }
XMLProperty* XMLProperty*
@ -568,16 +579,18 @@ XMLNode::add_property(const char* name, const long value)
} }
void void
XMLNode::remove_property(const string& n) XMLNode::remove_property(const string& name)
{ {
if (_propmap.find(n) != _propmap.end()) { XMLPropertyIterator iter = _proplist.begin();
XMLProperty* p = _propmap[n];
XMLPropertyIterator i = std::find(_proplist.begin(), _proplist.end(), p); while (iter != _proplist.end()) {
if (i != _proplist.end ()) { if ((*iter)->name() == name) {
_proplist.erase (i); XMLProperty* property = *iter;
_proplist.erase (iter);
delete property;
break;
} }
delete p; ++iter;
_propmap.erase(n);
} }
} }