Skip to content

Commit b4367af

Browse files
committed
Move make_region_name to events.hpp
1 parent d7ada9f commit b4367af

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

src/methods.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ extern "C"
3535
if (!PyArg_ParseTuple(args, "sssK", &module, &region_name, &file_name, &line_number))
3636
return NULL;
3737

38-
static std::string region = "";
39-
region = module;
40-
region += ":";
41-
region += region_name;
38+
const std::string& region = scorepy::make_region_name(module, region_name);
4239
scorepy::region_begin(region, module, file_name, line_number);
4340

4441
Py_RETURN_NONE;
@@ -55,10 +52,7 @@ extern "C"
5552
if (!PyArg_ParseTuple(args, "ss", &module, &region_name))
5653
return NULL;
5754

58-
static std::string region = "";
59-
region = module;
60-
region += ":";
61-
region += region_name;
55+
const std::string& region = scorepy::make_region_name(module, region_name);
6256
scorepy::region_end(region);
6357

6458
Py_RETURN_NONE;

src/scorepy/cInstrumenter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
namespace scorepy
99
{
10-
static const std::string& make_region_name(const char* moduleName, const char* name)
11-
{
12-
static std::string region;
13-
region = moduleName;
14-
region += ":";
15-
region += name;
16-
return region;
17-
}
1810

1911
void CInstrumenter::enable_instrumenter()
2012
{

src/scorepy/events.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
namespace scorepy
77
{
8+
/// Combine the arguments into a region name
9+
/// Return value is a statically allocated string to avoid memory (re)allocations
10+
inline const std::string& make_region_name(const char* module_name, const char* name)
11+
{
12+
static std::string region;
13+
region = module_name;
14+
region += ":";
15+
region += name;
16+
return region;
17+
}
18+
819
void region_begin(const std::string& region_name, std::string module, std::string file_name,
920
std::uint64_t line_number);
1021
void region_end(const std::string& region_name);

0 commit comments

Comments
 (0)