3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-03 13:07:58 +00:00

Make new_id/new_id_suffix taking string_view to avoid allocating strings

This commit is contained in:
Robert O'Callahan 2025-10-13 00:28:49 +00:00
parent 5cc3f27a5f
commit bf732df591
2 changed files with 8 additions and 8 deletions

View file

@ -295,35 +295,35 @@ void yosys_shutdown()
#endif #endif
} }
RTLIL::IdString new_id(std::string file, int line, std::string func) RTLIL::IdString new_id(std::string_view file, int line, std::string_view func)
{ {
#ifdef _WIN32 #ifdef _WIN32
size_t pos = file.find_last_of("/\\"); size_t pos = file.find_last_of("/\\");
#else #else
size_t pos = file.find_last_of('/'); size_t pos = file.find_last_of('/');
#endif #endif
if (pos != std::string::npos) if (pos != std::string_view::npos)
file = file.substr(pos+1); file = file.substr(pos+1);
pos = func.find_last_of(':'); pos = func.find_last_of(':');
if (pos != std::string::npos) if (pos != std::string_view::npos)
func = func.substr(pos+1); func = func.substr(pos+1);
return stringf("$auto$%s:%d:%s$%d", file, line, func, autoidx++); return stringf("$auto$%s:%d:%s$%d", file, line, func, autoidx++);
} }
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix) RTLIL::IdString new_id_suffix(std::string_view file, int line, std::string_view func, std::string_view suffix)
{ {
#ifdef _WIN32 #ifdef _WIN32
size_t pos = file.find_last_of("/\\"); size_t pos = file.find_last_of("/\\");
#else #else
size_t pos = file.find_last_of('/'); size_t pos = file.find_last_of('/');
#endif #endif
if (pos != std::string::npos) if (pos != std::string_view::npos)
file = file.substr(pos+1); file = file.substr(pos+1);
pos = func.find_last_of(':'); pos = func.find_last_of(':');
if (pos != std::string::npos) if (pos != std::string_view::npos)
func = func.substr(pos+1); func = func.substr(pos+1);
return stringf("$auto$%s:%d:%s$%s$%d", file, line, func, suffix, autoidx++); return stringf("$auto$%s:%d:%s$%s$%d", file, line, func, suffix, autoidx++);

View file

@ -271,8 +271,8 @@ extern int autoidx;
extern int yosys_xtrace; extern int yosys_xtrace;
extern bool yosys_write_versions; extern bool yosys_write_versions;
RTLIL::IdString new_id(std::string file, int line, std::string func); RTLIL::IdString new_id(std::string_view file, int line, std::string_view func);
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix); RTLIL::IdString new_id_suffix(std::string_view file, int line, std::string_view func, std::string_view suffix);
#define NEW_ID \ #define NEW_ID \
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__) YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)