Skip to content

Commit f30ba8b

Browse files
core(perf): use string move constructor for AddCustomContext (#2005)
Signed-off-by: romintomasetti <[email protected]>
1 parent 7f72775 commit f30ba8b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/benchmark/benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void RegisterProfilerManager(ProfilerManager* profiler_manager);
486486

487487
// Add a key-value pair to output as part of the context stanza in the report.
488488
BENCHMARK_EXPORT
489-
void AddCustomContext(const std::string& key, const std::string& value);
489+
void AddCustomContext(std::string key, std::string value);
490490

491491
namespace internal {
492492
class Benchmark;

src/benchmark.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,12 @@ void RegisterProfilerManager(ProfilerManager* manager) {
708708
internal::profiler_manager = manager;
709709
}
710710

711-
void AddCustomContext(const std::string& key, const std::string& value) {
711+
void AddCustomContext(std::string key, std::string value) {
712712
if (internal::global_context == nullptr) {
713713
internal::global_context = new std::map<std::string, std::string>();
714714
}
715-
if (!internal::global_context->emplace(key, value).second) {
715+
if (!internal::global_context->emplace(std::move(key), std::move(value))
716+
.second) {
716717
std::cerr << "Failed to add custom context \"" << key << "\" as it already "
717718
<< "exists with value \"" << value << "\"\n";
718719
}

0 commit comments

Comments
 (0)