diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2020-05-26 11:51:06 +0100 |
---|---|---|
committer | Rupert Swarbrick <rswarbrick@gmail.com> | 2020-05-26 12:27:15 +0100 |
commit | 8f87ccec9b6ed3c9bb8280830b506b28324a60d8 (patch) | |
tree | 531acf0469ad0ce2bac0f407563a67223aa67720 /kernel | |
parent | a7f2ef6d34c4b336a910b3c6f3d2cc11da8a82b4 (diff) | |
download | yosys-8f87ccec9b6ed3c9bb8280830b506b28324a60d8.tar.gz yosys-8f87ccec9b6ed3c9bb8280830b506b28324a60d8.tar.bz2 yosys-8f87ccec9b6ed3c9bb8280830b506b28324a60d8.zip |
Use c_str(), not str() for IdString/std::string == and != operators
These operators work by fetching the string from the global string
table and then comparing with the std::string that was passed in as
rhs.
Using str() means that we create a std::string (strlen; malloc;
memcpy), compare for equality (another memcmp if they have the same
length) and then finally free the string.
Using c_str() means that we pass the const char* straight to
std::string's equality operator. This ends up as a call to
std::string::compare (the const char* flavour), which is essentially
strcmp.
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/rtlil.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 11c45bbec..10bfc13f2 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -296,8 +296,8 @@ namespace RTLIL // The methods below are just convenience functions for better compatibility with std::string. - bool operator==(const std::string &rhs) const { return str() == rhs; } - bool operator!=(const std::string &rhs) const { return str() != rhs; } + bool operator==(const std::string &rhs) const { return c_str() == rhs; } + bool operator!=(const std::string &rhs) const { return c_str() != rhs; } bool operator==(const char *rhs) const { return strcmp(c_str(), rhs) == 0; } bool operator!=(const char *rhs) const { return strcmp(c_str(), rhs) != 0; } |