summaryrefslogtreecommitdiff
path: root/absl/container/internal/raw_hash_set_probe_benchmark.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-12-26 21:22:51 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-26 21:23:47 -0800
commitf9228ec834edef9b623d4824dd006890c203adc3 (patch)
treec41a1f543553fb5c8416005bfdb55048b2902d10 /absl/container/internal/raw_hash_set_probe_benchmark.cc
parentbd47468324e0db12aac9a57128d40fc23c233fb4 (diff)
Migrate static objects to NoDestructor in tests, testing libraries and benchmarks.
PiperOrigin-RevId: 593918110 Change-Id: Ide100c69b10e28011af17c7f82bb10eea072cad4
Diffstat (limited to 'absl/container/internal/raw_hash_set_probe_benchmark.cc')
-rw-r--r--absl/container/internal/raw_hash_set_probe_benchmark.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/absl/container/internal/raw_hash_set_probe_benchmark.cc b/absl/container/internal/raw_hash_set_probe_benchmark.cc
index 7169a2e2..5d4184b2 100644
--- a/absl/container/internal/raw_hash_set_probe_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_probe_benchmark.cc
@@ -19,6 +19,7 @@
#include <regex> // NOLINT
#include <vector>
+#include "absl/base/no_destructor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/internal/hash_function_defaults.h"
#include "absl/container/internal/hashtable_debug.h"
@@ -29,6 +30,7 @@
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
+#include "absl/types/optional.h"
namespace {
@@ -71,7 +73,7 @@ struct Policy {
};
absl::BitGen& GlobalBitGen() {
- static auto* value = new absl::BitGen;
+ static absl::NoDestructor<absl::BitGen> value;
return *value;
}
@@ -112,7 +114,7 @@ class RandomizedAllocator {
static constexpr size_t kRandomPool = 20;
static std::vector<T*>& GetPointers(size_t n) {
- static auto* m = new absl::flat_hash_map<size_t, std::vector<T*>>();
+ static absl::NoDestructor<absl::flat_hash_map<size_t, std::vector<T*>>> m;
return (*m)[n];
}
};
@@ -460,12 +462,12 @@ constexpr int kNameWidth = 15;
constexpr int kDistWidth = 16;
bool CanRunBenchmark(absl::string_view name) {
- static std::regex* const filter = []() -> std::regex* {
+ static const absl::NoDestructor<absl::optional<std::regex>> filter([] {
return benchmarks.empty() || benchmarks == "all"
- ? nullptr
- : new std::regex(std::string(benchmarks));
- }();
- return filter == nullptr || std::regex_search(std::string(name), *filter);
+ ? absl::nullopt
+ : absl::make_optional(std::regex(std::string(benchmarks)));
+ }());
+ return !filter->has_value() || std::regex_search(std::string(name), **filter);
}
struct Result {