bench, refactor: Use `std::string_view` for `BenchRunner` ctor parameter
What changed, and why it matters
This is a minor code cleanup in Bitcoin Core's internal benchmarking (performance testing) code. It changes a function parameter from std::string to std::string_view to avoid unnecessary header includes. There is no security relevance.
No security action required. This is a benign refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors BenchRunner’s constructor to accept std::string_view instead of std::string. This eliminates implicit std::string conversions from string literals in the BENCHMARK() macro and removes the need to include
Changed components
src/bench/bench.cppsrc/bench/bench.hInspect captured patch +5 / −3
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 45d1b360..7ed425c4 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -15,6 +15,7 @@
#include <iostream>
#include <regex>
#include <string>
+#include <string_view>
#include <utility>
#include <vector>
@@ -68,9 +69,9 @@ BenchRunner::BenchmarkMap& BenchRunner::benchmarks()
return benchmarks_map;
}
-BenchRunner::BenchRunner(std::string name, BenchFunction func)
+BenchRunner::BenchRunner(std::string_view name, BenchFunction func)
{
- Assert(benchmarks().try_emplace(std::move(name), std::move(func)).second);
+ Assert(benchmarks().try_emplace(std::string{name}, std::move(func)).second);
}
void BenchRunner::RunAll(const Args& args)
diff --git a/src/bench/bench.h b/src/bench/bench.h
index f7df42a3..9212c81d 100644
--- a/src/bench/bench.h
+++ b/src/bench/bench.h
@@ -13,6 +13,7 @@
#include <functional>
#include <map>
#include <string>
+#include <string_view>
#include <vector>
/*
@@ -58,7 +59,7 @@ class BenchRunner
static BenchmarkMap& benchmarks();
public:
- BenchRunner(std::string name, BenchFunction func);
+ BenchRunner(std::string_view name, BenchFunction func);
static void RunAll(const Args& args);
};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.