optimized `Library::detectContainerInternal()` a bit (#5333)
Scanning `cli/filelister.cpp` with `DISABLE_VALUEFLOW=1` and `--enable=all -Ilib -D__GNUC__` Clang 15 `111,300,996` -> `106,883,955` GCC 13 `110,555,879` -> `105,983,608`
This commit is contained in:
parent
8b309a8829
commit
6a263ba026
|
@ -419,7 +419,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
|
|
||||||
const char* const inherits = node->Attribute("inherits");
|
const char* const inherits = node->Attribute("inherits");
|
||||||
if (inherits) {
|
if (inherits) {
|
||||||
const std::map<std::string, Container>::const_iterator i = containers.find(inherits);
|
const std::unordered_map<std::string, Container>::const_iterator i = containers.find(inherits);
|
||||||
if (i != containers.end())
|
if (i != containers.end())
|
||||||
container = i->second; // Take values from parent and overwrite them if necessary
|
container = i->second; // Take values from parent and overwrite them if necessary
|
||||||
else
|
else
|
||||||
|
@ -1158,8 +1158,17 @@ bool Library::isScopeNoReturn(const Token *end, std::string *unknownFunc) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Library::Container* Library::detectContainerInternal(const Token* typeStart, DetectContainer detect, bool* isIterator, bool withoutStd) const
|
const Library::Container* Library::detectContainerInternal(const Token* const typeStart, DetectContainer detect, bool* isIterator, bool withoutStd) const
|
||||||
{
|
{
|
||||||
|
const Token* firstLinkedTok = nullptr;
|
||||||
|
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
|
||||||
|
if (!tok->link())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
firstLinkedTok = tok;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (const std::pair<const std::string, Library::Container> & c : containers) {
|
for (const std::pair<const std::string, Library::Container> & c : containers) {
|
||||||
const Container& container = c.second;
|
const Container& container = c.second;
|
||||||
if (container.startPattern.empty())
|
if (container.startPattern.empty())
|
||||||
|
@ -1177,24 +1186,23 @@ const Library::Container* Library::detectContainerInternal(const Token* typeStar
|
||||||
return &container;
|
return &container;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
|
if (!firstLinkedTok)
|
||||||
if (!tok->link())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const bool matchedStartPattern = Token::Match(typeStart, container.startPattern2.c_str() + offset);
|
const bool matchedStartPattern = Token::Match(typeStart, container.startPattern2.c_str() + offset);
|
||||||
|
if (!matchedStartPattern)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (detect != ContainerOnly && matchedStartPattern && Token::Match(tok->link(), container.itEndPattern.c_str())) {
|
if (detect != ContainerOnly && Token::Match(firstLinkedTok->link(), container.itEndPattern.c_str())) {
|
||||||
if (isIterator)
|
if (isIterator)
|
||||||
*isIterator = true;
|
*isIterator = true;
|
||||||
return &container;
|
return &container;
|
||||||
}
|
}
|
||||||
if (detect != IteratorOnly && matchedStartPattern && Token::Match(tok->link(), container.endPattern.c_str())) {
|
if (detect != IteratorOnly && Token::Match(firstLinkedTok->link(), container.endPattern.c_str())) {
|
||||||
if (isIterator)
|
if (isIterator)
|
||||||
*isIterator = false;
|
*isIterator = false;
|
||||||
return &container;
|
return &container;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ public:
|
||||||
static Yield yieldFrom(const std::string& yieldName);
|
static Yield yieldFrom(const std::string& yieldName);
|
||||||
static Action actionFrom(const std::string& actionName);
|
static Action actionFrom(const std::string& actionName);
|
||||||
};
|
};
|
||||||
std::map<std::string, Container> containers;
|
std::unordered_map<std::string, Container> containers;
|
||||||
const Container* detectContainer(const Token* typeStart) const;
|
const Container* detectContainer(const Token* typeStart) const;
|
||||||
const Container* detectIterator(const Token* typeStart) const;
|
const Container* detectIterator(const Token* typeStart) const;
|
||||||
const Container* detectContainerOrIterator(const Token* typeStart, bool* isIterator = nullptr, bool withoutStd = false) const;
|
const Container* detectContainerOrIterator(const Token* typeStart, bool* isIterator = nullptr, bool withoutStd = false) const;
|
||||||
|
|
Loading…
Reference in New Issue