aboutsummaryrefslogtreecommitdiffstats
path: root/passes
diff options
context:
space:
mode:
authorRupert Swarbrick <rswarbrick@gmail.com>2020-05-27 09:36:33 +0100
committerRupert Swarbrick <rswarbrick@gmail.com>2020-05-27 09:36:33 +0100
commit061d1f0c07623d741e56a36e7a3e5cd48da30d5a (patch)
tree4a1e5e4e8fe4ebb1c5c88142016f00f36abf5351 /passes
parent0d9beb5b2eec3ba839faa58a1a775311d9c3376c (diff)
downloadyosys-061d1f0c07623d741e56a36e7a3e5cd48da30d5a.tar.gz
yosys-061d1f0c07623d741e56a36e7a3e5cd48da30d5a.tar.bz2
yosys-061d1f0c07623d741e56a36e7a3e5cd48da30d5a.zip
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)
Diffstat (limited to 'passes')
-rw-r--r--passes/cmds/select.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/passes/cmds/select.cc b/passes/cmds/select.cc
index c5ef72b1c..f79f979de 100644
--- a/passes/cmds/select.cc
+++ b/passes/cmds/select.cc
@@ -30,22 +30,24 @@ using RTLIL::id2cstr;
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)
return true;
+
const char *id_c = id.c_str();
- if (*id_c == '\\' &&
- id.size() == 1 + pattern.size() &&
- memcmp(id_c + 1, pattern.c_str(), pattern.size()) == 0)
+ const char *pat_c = pattern.c_str();
+ size_t id_size = strlen(id_c);
+ 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;
- if (patmatch(pattern.c_str(), id.c_str()))
+ if (patmatch(pat_c, id_c))
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;
- if (id.size() > 0 && id[0] == '$' && pattern.size() > 0 && pattern[0] == '$') {
- const char *p = id.c_str();
- const char *q = strrchr(p, '$');
+ if (*id_c == '$' && *pat_c == '$') {
+ const char *q = strrchr(id_c, '$');
if (pattern == q)
return true;
}