Skip to content

Commit aa99660

Browse files
committed
Make new_id/new_id_suffix taking string_view to avoid allocating strings
1 parent b7bd8a5 commit aa99660

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

kernel/yosys.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,35 +295,35 @@ void yosys_shutdown()
295295
#endif
296296
}
297297

298-
RTLIL::IdString new_id(std::string file, int line, std::string func)
298+
RTLIL::IdString new_id(std::string_view file, int line, std::string_view func)
299299
{
300300
#ifdef _WIN32
301301
size_t pos = file.find_last_of("/\\");
302302
#else
303303
size_t pos = file.find_last_of('/');
304304
#endif
305-
if (pos != std::string::npos)
305+
if (pos != std::string_view::npos)
306306
file = file.substr(pos+1);
307307

308308
pos = func.find_last_of(':');
309-
if (pos != std::string::npos)
309+
if (pos != std::string_view::npos)
310310
func = func.substr(pos+1);
311311

312312
return stringf("$auto$%s:%d:%s$%d", file, line, func, autoidx++);
313313
}
314314

315-
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix)
315+
RTLIL::IdString new_id_suffix(std::string_view file, int line, std::string_view func, std::string_view suffix)
316316
{
317317
#ifdef _WIN32
318318
size_t pos = file.find_last_of("/\\");
319319
#else
320320
size_t pos = file.find_last_of('/');
321321
#endif
322-
if (pos != std::string::npos)
322+
if (pos != std::string_view::npos)
323323
file = file.substr(pos+1);
324324

325325
pos = func.find_last_of(':');
326-
if (pos != std::string::npos)
326+
if (pos != std::string_view::npos)
327327
func = func.substr(pos+1);
328328

329329
return stringf("$auto$%s:%d:%s$%s$%d", file, line, func, suffix, autoidx++);

kernel/yosys_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ extern int autoidx;
271271
extern int yosys_xtrace;
272272
extern bool yosys_write_versions;
273273

274-
RTLIL::IdString new_id(std::string file, int line, std::string func);
275-
RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix);
274+
RTLIL::IdString new_id(std::string_view file, int line, std::string_view func);
275+
RTLIL::IdString new_id_suffix(std::string_view file, int line, std::string_view func, std::string_view suffix);
276276

277277
#define NEW_ID \
278278
YOSYS_NAMESPACE_PREFIX new_id(__FILE__, __LINE__, __FUNCTION__)

0 commit comments

Comments
 (0)