Skip to content

Commit d5d3132

Browse files
committed
Do not pass std::string_view as reference
1 parent 6cad26e commit d5d3132

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/scorepy/cInstrumenter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ bool CInstrumenter::on_event(PyFrameObject& frame, int what, PyObject*)
119119
bool success = try_region_begin(code);
120120
if (!success)
121121
{
122-
std::string_view name = compat::get_string_as_utf_8(code->co_name);
123-
std::string_view module_name = get_module_name(frame);
122+
const auto name = compat::get_string_as_utf_8(code->co_name);
123+
const auto module_name = get_module_name(frame);
124124
if (name.compare("_unsetprofile") != 0 && module_name.compare(0, 6, "scorep") != 0)
125125
{
126126
const int line_number = code->co_firstlineno;
@@ -137,10 +137,10 @@ bool CInstrumenter::on_event(PyFrameObject& frame, int what, PyObject*)
137137
bool success = try_region_end(code);
138138
if (!success)
139139
{
140-
std::string_view name = compat::get_string_as_utf_8(code->co_name);
141-
std::string_view module_name = get_module_name(frame);
140+
const auto name = compat::get_string_as_utf_8(code->co_name);
141+
const auto module_name = get_module_name(frame);
142142
// TODO: Use string_view/CString comparison?
143-
if (std::string(name) != "_unsetprofile" && std::string(module_name, 0, 6) != "scorep")
143+
if (name.compare("_unsetprofile") != 0 && module_name.compare(0, 6, "scorep") != 0)
144144
{
145145
region_end(name, module_name, code);
146146
}

src/scorepy/events.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ static compat::RegisterCodeDealloc register_dealloc(on_dealloc);
2828

2929
// Used for regions, that have an identifier, aka a code object id. (instrumenter regions and
3030
// some decorated regions)
31-
void region_begin(std::string_view& function_name, std::string_view& module,
31+
void region_begin(std::string_view function_name, std::string_view module,
3232
const std::string& file_name, const std::uint64_t line_number,
3333
compat::PyCodeObject* identifier)
3434
{
3535
region_handle& region = regions[identifier];
3636

3737
if (region == uninitialised_region_handle)
3838
{
39-
auto& region_name = make_region_name(module, function_name);
39+
const auto region_name = make_region_name(module, function_name);
4040
SCOREP_User_RegionInit(&region.value, NULL, NULL, region_name.c_str(),
4141
SCOREP_USER_REGION_TYPE_FUNCTION, file_name.c_str(), line_number);
4242

@@ -47,10 +47,10 @@ void region_begin(std::string_view& function_name, std::string_view& module,
4747

4848
// Used for regions, that only have a function name, a module, a file and a line number (user
4949
// regions)
50-
void region_begin(std::string_view& function_name, std::string_view& module,
50+
void region_begin(std::string_view function_name, std::string_view module,
5151
const std::string& file_name, const std::uint64_t line_number)
5252
{
53-
std::string region_name = make_region_name(module, function_name);
53+
const auto region_name = make_region_name(module, function_name);
5454
region_handle& region = user_regions[region_name];
5555

5656
if (region == uninitialised_region_handle)
@@ -65,7 +65,7 @@ void region_begin(std::string_view& function_name, std::string_view& module,
6565

6666
// Used for regions, that have an identifier, aka a code object id. (instrumenter regions and
6767
// some decorated regions)
68-
void region_end(std::string_view& function_name, std::string_view& module,
68+
void region_end(std::string_view function_name, std::string_view module,
6969
compat::PyCodeObject* identifier)
7070
{
7171
const auto it_region = regions.find(identifier);
@@ -75,15 +75,15 @@ void region_end(std::string_view& function_name, std::string_view& module,
7575
}
7676
else
7777
{
78-
std::string region_name = make_region_name(module, function_name);
78+
const auto region_name = make_region_name(module, function_name);
7979
region_end_error_handling(region_name);
8080
}
8181
}
8282

8383
// Used for regions, that only have a function name, a module (user regions)
84-
void region_end(std::string_view& function_name, std::string_view& module)
84+
void region_end(std::string_view function_name, std::string_view module)
8585
{
86-
std::string region_name = make_region_name(module, function_name);
86+
const auto region_name = make_region_name(module, function_name);
8787
auto it_region = user_regions.find(region_name);
8888
if (it_region != user_regions.end())
8989
{

src/scorepy/events.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ struct region_handle
3030
constexpr region_handle uninitialised_region_handle = region_handle();
3131

3232
/// Combine the arguments into a region name
33-
/// Return value is a statically allocated string to avoid memory (re)allocations
34-
inline const std::string& make_region_name(std::string_view& module_name, std::string_view& name)
33+
inline std::string make_region_name(std::string_view module_name, std::string_view name)
3534
{
36-
static std::string region;
37-
region = module_name;
35+
std::string region;
36+
region += module_name;
3837
region += ":";
3938
region += name;
40-
return region;
39+
return std::move(region);
4140
}
4241

4342
extern std::unordered_map<compat::PyCodeObject*, region_handle> regions;
@@ -59,10 +58,10 @@ inline bool try_region_begin(compat::PyCodeObject* identifier)
5958
}
6059
}
6160

62-
void region_begin(std::string_view& function_name, std::string_view& module,
61+
void region_begin(std::string_view function_name, std::string_view module,
6362
const std::string& file_name, const std::uint64_t line_number,
6463
compat::PyCodeObject* identifier);
65-
void region_begin(std::string_view& function_name, std::string_view& module,
64+
void region_begin(std::string_view function_name, std::string_view module,
6665
const std::string& file_name, const std::uint64_t line_number);
6766

6867
/** tries to end a region. Return true on success
@@ -82,9 +81,9 @@ inline bool try_region_end(compat::PyCodeObject* identifier)
8281
}
8382
}
8483

85-
void region_end(std::string_view& function_name, std::string_view& module,
84+
void region_end(std::string_view function_name, std::string_view module,
8685
compat::PyCodeObject* identifier);
87-
void region_end(std::string_view& function_name, std::string_view& module);
86+
void region_end(std::string_view function_name, std::string_view module);
8887

8988
void region_end_error_handling(const std::string& region_name);
9089

0 commit comments

Comments
 (0)