3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-22 13:41:27 +00:00

Make IdString::begins_width/ends_with take std::string_view so we avoid a strlen when the parameter is a string constant

This commit is contained in:
Robert O'Callahan 2025-10-16 03:37:49 +00:00 committed by Emil J. Tywoniak
parent 5f76729cbb
commit 2319d82efb

View file

@ -405,16 +405,15 @@ struct RTLIL::IdString
return strncmp(c_str()+pos, s, len);
}
bool begins_with(const char* prefix) const {
size_t len = strlen(prefix);
if (size() < len) return false;
return compare(0, len, prefix) == 0;
bool begins_with(std::string_view prefix) const {
if (size() < prefix.size()) return false;
return compare(0, prefix.size(), prefix.data()) == 0;
}
bool ends_with(const char* suffix) const {
size_t len = strlen(suffix);
if (size() < len) return false;
return compare(size()-len, len, suffix) == 0;
bool ends_with(std::string_view suffix) const {
size_t sz = size();
if (sz < suffix.size()) return false;
return compare(sz - suffix.size(), suffix.size(), suffix.data()) == 0;
}
bool contains(const char* str) const {