Use ununordered_map instead of map
Should result in a performance boost when reading large files.
This commit is contained in:
parent
c51d9d5b30
commit
642fbe815d
|
@ -119,7 +119,7 @@ void dx_iface::writeHeader(DRW_Header &data){
|
|||
//complete copy of header vars:
|
||||
data = cData.headerC;
|
||||
//or copy one by one:
|
||||
// for (std::map<std::string,DRW_Variant*>::iterator it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it)
|
||||
// for (auto it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it)
|
||||
// data.vars[it->first] = new DRW_Variant( *(it->second) );
|
||||
}
|
||||
|
||||
|
|
|
@ -1662,8 +1662,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
|
|||
}
|
||||
|
||||
#ifdef DRW_DBG
|
||||
std::map<std::string,DRW_Variant *>::const_iterator it;
|
||||
for ( it=vars.begin() ; it != vars.end(); ++it ){
|
||||
for ( auto it=vars.begin() ; it != vars.end(); ++it ){
|
||||
DRW_DBG((*it).first); DRW_DBG("\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -1703,8 +1702,7 @@ void DRW_Header::addCoord(std::string key, DRW_Coord value, int code){
|
|||
|
||||
bool DRW_Header::getDouble(std::string key, double *varDouble){
|
||||
bool result = false;
|
||||
std::map<std::string,DRW_Variant *>::iterator it;
|
||||
it=vars.find( key);
|
||||
auto it=vars.find( key);
|
||||
if (it != vars.end()) {
|
||||
DRW_Variant *var = (*it).second;
|
||||
if (var->type == DRW_Variant::DOUBLE) {
|
||||
|
@ -1719,8 +1717,7 @@ bool DRW_Header::getDouble(std::string key, double *varDouble){
|
|||
|
||||
bool DRW_Header::getInt(std::string key, int *varInt){
|
||||
bool result = false;
|
||||
std::map<std::string,DRW_Variant *>::iterator it;
|
||||
it=vars.find( key);
|
||||
auto it=vars.find( key);
|
||||
if (it != vars.end()) {
|
||||
DRW_Variant *var = (*it).second;
|
||||
if (var->type == DRW_Variant::INTEGER) {
|
||||
|
@ -1735,8 +1732,7 @@ bool DRW_Header::getInt(std::string key, int *varInt){
|
|||
|
||||
bool DRW_Header::getStr(std::string key, std::string *varStr){
|
||||
bool result = false;
|
||||
std::map<std::string,DRW_Variant *>::iterator it;
|
||||
it=vars.find( key);
|
||||
auto it=vars.find( key);
|
||||
if (it != vars.end()) {
|
||||
DRW_Variant *var = (*it).second;
|
||||
if (var->type == DRW_Variant::STRING) {
|
||||
|
@ -1751,8 +1747,7 @@ bool DRW_Header::getStr(std::string key, std::string *varStr){
|
|||
|
||||
bool DRW_Header::getCoord(std::string key, DRW_Coord *varCoord){
|
||||
bool result = false;
|
||||
std::map<std::string,DRW_Variant *>::iterator it;
|
||||
it=vars.find( key);
|
||||
auto it=vars.find( key);
|
||||
if (it != vars.end()) {
|
||||
DRW_Variant *var = (*it).second;
|
||||
if (var->type == DRW_Variant::COORD) {
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
vportCtrl(),
|
||||
vpEntHeaderCtrl()
|
||||
{
|
||||
for (std::map<std::string,DRW_Variant*>::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it)
|
||||
for (auto it=h.vars.begin(); it!=h.vars.end(); ++it)
|
||||
{
|
||||
this->vars[it->first] = new DRW_Variant( *(it->second) );
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public:
|
|||
clearVars();
|
||||
this->version = h.version;
|
||||
this->comments = h.comments;
|
||||
for (std::map<std::string,DRW_Variant*>::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it)
|
||||
for (auto it=h.vars.begin(); it!=h.vars.end(); ++it)
|
||||
{
|
||||
this->vars[it->first] = new DRW_Variant( *(it->second) );
|
||||
}
|
||||
|
@ -92,14 +92,16 @@ private:
|
|||
bool getCoord(std::string key, DRW_Coord *varCoord);
|
||||
void clearVars()
|
||||
{
|
||||
for (std::map<std::string,DRW_Variant*>::iterator it=vars.begin(); it!=vars.end(); ++it)
|
||||
for (auto it=vars.begin(); it!=vars.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
vars.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
std::map<std::string,DRW_Variant*> vars;
|
||||
std::unordered_map<std::string,DRW_Variant*> vars;
|
||||
private:
|
||||
std::string comments;
|
||||
std::string name;
|
||||
|
|
|
@ -1761,8 +1761,7 @@ bool dxfRW::writeObjects() {
|
|||
//write IMAGEDEF_REACTOR
|
||||
for (unsigned int i=0; i<imageDef.size(); i++) {
|
||||
DRW_ImageDef *id = imageDef.at(i);
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for ( it=id->reactors.begin() ; it != id->reactors.end(); ++it ) {
|
||||
for (auto it=id->reactors.begin() ; it != id->reactors.end(); ++it ) {
|
||||
writer->writeString(0, "IMAGEDEF_REACTOR");
|
||||
writer->writeString(5, (*it).first);
|
||||
writer->writeString(330, (*it).second);
|
||||
|
@ -1795,7 +1794,7 @@ bool dxfRW::writeObjects() {
|
|||
}
|
||||
writer->writeString(102, "{ACAD_REACTORS");
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
for ( it=id->reactors.begin() ; it != id->reactors.end(); ++it ) {
|
||||
for (auto it=id->reactors.begin() ; it != id->reactors.end(); ++it ) {
|
||||
writer->writeString(330, (*it).first);
|
||||
}
|
||||
writer->writeString(102, "}");
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define LIBDXFRW_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "drw_entities.h"
|
||||
#include "drw_objects.h"
|
||||
#include "drw_header.h"
|
||||
|
@ -141,7 +142,7 @@ private:
|
|||
bool applyExt;
|
||||
bool writingBlock;
|
||||
int elParts; /*!< parts munber when convert ellipse to polyline */
|
||||
std::map<std::string,int> blockMap;
|
||||
std::unordered_map<std::string,int> blockMap;
|
||||
std::vector<DRW_ImageDef*> imageDef; /*!< imageDef list */
|
||||
|
||||
int currHandle;
|
||||
|
|
Loading…
Reference in New Issue
Block a user