From 2319d82efbec1f9f1f06fd3d7a338aafa4a0904a Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 16 Oct 2025 03:37:49 +0000 Subject: [PATCH] Make IdString::begins_width/ends_with take std::string_view so we avoid a strlen when the parameter is a string constant --- kernel/rtlil.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 27f610f85..85e89686e 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -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 {