Optimize IfcFile::entitiesByReference() by reserving capacity for IfcEntityList in advance.

Around 18.4 % speed-up (avg. of first 2000 calls) when converting a somewhat large (176 MB) file to XML.
This commit is contained in:
Stinkfist0
2018-09-28 15:00:48 +03:00
committed by Thomas Krijnen
parent 40c2602b0e
commit 38f7ccdc20
3 changed files with 7 additions and 6 deletions
+1
View File
@@ -40,6 +40,7 @@ public:
it end(); it end();
IfcUtil::IfcBaseClass* operator[] (int i); IfcUtil::IfcBaseClass* operator[] (int i);
unsigned int size() const; unsigned int size() const;
void reserve(unsigned capacity);
bool contains(IfcUtil::IfcBaseClass*) const; bool contains(IfcUtil::IfcBaseClass*) const;
template <class U> template <class U>
typename U::list::ptr as() { typename U::list::ptr as() {
+5 -6
View File
@@ -1793,17 +1793,16 @@ IfcEntityList::ptr IfcFile::entitiesByType(const std::string& t) {
IfcEntityList::ptr IfcFile::entitiesByReference(int t) { IfcEntityList::ptr IfcFile::entitiesByReference(int t) {
entities_by_ref_t::const_iterator it = byref.find(t); entities_by_ref_t::const_iterator it = byref.find(t);
IfcEntityList::ptr return_value; IfcEntityList::ptr ret;
if (it != byref.end()) { if (it != byref.end()) {
ret.reset(new IfcEntityList);
ret->reserve((unsigned)it->second.size());
const std::vector<unsigned>& ids = it->second; const std::vector<unsigned>& ids = it->second;
for (std::vector<unsigned>::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) { for (std::vector<unsigned>::const_iterator jt = ids.begin(); jt != ids.end(); ++jt) {
if (!return_value) { ret->push(entityById(*jt));
return_value.reset(new IfcEntityList);
}
return_value->push(entityById(*jt));
} }
} }
return return_value; return ret;
} }
IfcUtil::IfcBaseClass* IfcFile::entityById(int id) { IfcUtil::IfcBaseClass* IfcFile::entityById(int id) {
+1
View File
@@ -48,6 +48,7 @@ void IfcEntityList::push(const IfcEntityList::ptr& l) {
} }
} }
unsigned int IfcEntityList::size() const { return (unsigned int) ls.size(); } unsigned int IfcEntityList::size() const { return (unsigned int) ls.size(); }
void IfcEntityList::reserve(unsigned capacity) { ls.reserve((size_t)capacity); }
IfcEntityList::it IfcEntityList::begin() { return ls.begin(); } IfcEntityList::it IfcEntityList::begin() { return ls.begin(); }
IfcEntityList::it IfcEntityList::end() { return ls.end(); } IfcEntityList::it IfcEntityList::end() { return ls.end(); }
IfcUtil::IfcBaseClass* IfcEntityList::operator[] (int i) { IfcUtil::IfcBaseClass* IfcEntityList::operator[] (int i) {