mirror of https://github.com/YosysHQ/yosys.git
Minor optimisations in select.cc's match_ids function
- Pass a string argument by reference - Avoid multiple calls to IdString::str and IdString::c_str - Avoid combining checks for size > 0 and first char (C strings are null terminated, so foo[0] != '\0' implies that foo has positive length)
This commit is contained in:
parent
0d9beb5b2e
commit
061d1f0c07
|
@ -30,22 +30,24 @@ using RTLIL::id2cstr;
|
||||||
|
|
||||||
static std::vector<RTLIL::Selection> work_stack;
|
static std::vector<RTLIL::Selection> work_stack;
|
||||||
|
|
||||||
static bool match_ids(RTLIL::IdString id, std::string pattern)
|
static bool match_ids(RTLIL::IdString id, const std::string &pattern)
|
||||||
{
|
{
|
||||||
if (id == pattern)
|
if (id == pattern)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const char *id_c = id.c_str();
|
const char *id_c = id.c_str();
|
||||||
if (*id_c == '\\' &&
|
const char *pat_c = pattern.c_str();
|
||||||
id.size() == 1 + pattern.size() &&
|
size_t id_size = strlen(id_c);
|
||||||
memcmp(id_c + 1, pattern.c_str(), pattern.size()) == 0)
|
size_t pat_size = pattern.size();
|
||||||
|
|
||||||
|
if (*id_c == '\\' && id_size == 1 + pat_size && memcmp(id_c + 1, pat_c, pat_size) == 0)
|
||||||
return true;
|
return true;
|
||||||
if (patmatch(pattern.c_str(), id.c_str()))
|
if (patmatch(pat_c, id_c))
|
||||||
return true;
|
return true;
|
||||||
if (id.size() > 0 && id[0] == '\\' && patmatch(pattern.c_str(), id.substr(1).c_str()))
|
if (*id_c == '\\' && patmatch(pat_c, id_c + 1))
|
||||||
return true;
|
return true;
|
||||||
if (id.size() > 0 && id[0] == '$' && pattern.size() > 0 && pattern[0] == '$') {
|
if (*id_c == '$' && *pat_c == '$') {
|
||||||
const char *p = id.c_str();
|
const char *q = strrchr(id_c, '$');
|
||||||
const char *q = strrchr(p, '$');
|
|
||||||
if (pattern == q)
|
if (pattern == q)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue