library.cpp: optimized Library::detectContainer() (#1778)

* library.cpp: optimized Library::detectContainer()

reduces Ir from 5882 to 1149 according to callgrind

* fixed hang in tests
This commit is contained in:
Oliver Stöneberg 2019-04-06 06:42:01 +02:00 committed by Daniel Marjamäki
parent 6ab6cfe42f
commit 16ebb90b32
3 changed files with 7 additions and 6 deletions

View File

@ -381,8 +381,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
} }
const char* const startPattern = node->Attribute("startPattern"); const char* const startPattern = node->Attribute("startPattern");
if (startPattern) if (startPattern) {
container.startPattern = startPattern; container.startPattern = startPattern;
container.startPattern2 = container.startPattern + " !!::";
}
const char* const endPattern = node->Attribute("endPattern"); const char* const endPattern = node->Attribute("endPattern");
if (endPattern) if (endPattern)
container.endPattern = endPattern; container.endPattern = endPattern;
@ -1012,10 +1014,7 @@ const Library::Container* Library::detectContainer(const Token* typeStart, bool
if (container.startPattern.empty()) if (container.startPattern.empty())
continue; continue;
if (!endsWith(container.startPattern, '<')) { if (!Token::Match(typeStart, container.startPattern2.c_str()))
if (!Token::Match(typeStart, (container.startPattern + " !!::").c_str()))
continue;
} else if (!Token::Match(typeStart, (container.startPattern + " !!::").c_str()))
continue; continue;
if (!iterator && container.endPattern.empty()) // If endPattern is undefined, it will always match, but itEndPattern has to be defined. if (!iterator && container.endPattern.empty()) // If endPattern is undefined, it will always match, but itEndPattern has to be defined.

View File

@ -196,7 +196,7 @@ public:
Action action; Action action;
Yield yield; Yield yield;
}; };
std::string startPattern, endPattern, itEndPattern; std::string startPattern, startPattern2, endPattern, itEndPattern;
std::map<std::string, Function> functions; std::map<std::string, Function> functions;
int type_templateArgNo; int type_templateArgNo;
int size_templateArgNo; int size_templateArgNo;

View File

@ -6113,6 +6113,7 @@ private:
Settings sC; Settings sC;
Library::Container c; Library::Container c;
c.startPattern = "C"; c.startPattern = "C";
c.startPattern2 = "C !!::";
sC.library.containers["C"] = c; sC.library.containers["C"] = c;
ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC)); ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC));
ASSERT_EQUALS("container(C) *", typeOf("x=(C*)c;","(","test.cpp",&sC)); ASSERT_EQUALS("container(C) *", typeOf("x=(C*)c;","(","test.cpp",&sC));
@ -6122,6 +6123,7 @@ private:
Settings set; Settings set;
Library::Container vector; Library::Container vector;
vector.startPattern = "Vector"; vector.startPattern = "Vector";
vector.startPattern2 = "Vector !!::";
vector.type_templateArgNo = 0; vector.type_templateArgNo = 0;
vector.arrayLike_indexOp = true; vector.arrayLike_indexOp = true;
set.library.containers["Vector"] = vector; set.library.containers["Vector"] = vector;