diff options
Diffstat (limited to 'absl/container')
-rw-r--r-- | absl/container/BUILD.bazel | 4 | ||||
-rw-r--r-- | absl/container/CMakeLists.txt | 2 | ||||
-rw-r--r-- | absl/container/internal/container_memory_test.cc | 3 | ||||
-rw-r--r-- | absl/container/internal/hash_generator_testing.cc | 12 | ||||
-rw-r--r-- | absl/container/internal/raw_hash_set_probe_benchmark.cc | 16 |
5 files changed, 24 insertions, 13 deletions
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index d2910ed8..0ba2fa76 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel @@ -403,6 +403,7 @@ cc_test( deps = [ ":container_memory", ":test_instance_tracker", + "//absl/base:no_destructor", "//absl/meta:type_traits", "//absl/strings", "@com_google_googletest//:gtest", @@ -453,6 +454,7 @@ cc_library( linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":hash_policy_testing", + "//absl/base:no_destructor", "//absl/memory", "//absl/meta:type_traits", "//absl/strings", @@ -732,10 +734,12 @@ cc_binary( ":hash_function_defaults", ":hashtable_debug", ":raw_hash_set", + "//absl/base:no_destructor", "//absl/random", "//absl/random:distributions", "//absl/strings", "//absl/strings:str_format", + "//absl/types:optional", ], ) diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt index 60afdb2b..128cc0e9 100644 --- a/absl/container/CMakeLists.txt +++ b/absl/container/CMakeLists.txt @@ -450,6 +450,7 @@ absl_cc_test( ${ABSL_TEST_COPTS} DEPS absl::container_memory + absl::no_destructor absl::strings absl::test_instance_tracker absl::type_traits @@ -503,6 +504,7 @@ absl_cc_library( absl::hash_policy_testing absl::memory absl::meta + absl::no_destructor absl::strings TESTONLY ) diff --git a/absl/container/internal/container_memory_test.cc b/absl/container/internal/container_memory_test.cc index c1e57834..90d64bf5 100644 --- a/absl/container/internal/container_memory_test.cc +++ b/absl/container/internal/container_memory_test.cc @@ -25,6 +25,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "absl/base/no_destructor.h" #include "absl/container/internal/test_instance_tracker.h" #include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" @@ -58,7 +59,7 @@ TEST(Memory, AlignmentSmallerThanBase) { } std::map<std::type_index, int>& AllocationMap() { - static auto* map = new std::map<std::type_index, int>; + static absl::NoDestructor<std::map<std::type_index, int>> map; return *map; } diff --git a/absl/container/internal/hash_generator_testing.cc b/absl/container/internal/hash_generator_testing.cc index 59cc5aac..e89dfdb5 100644 --- a/absl/container/internal/hash_generator_testing.cc +++ b/absl/container/internal/hash_generator_testing.cc @@ -16,6 +16,8 @@ #include <deque> +#include "absl/base/no_destructor.h" + namespace absl { ABSL_NAMESPACE_BEGIN namespace container_internal { @@ -41,11 +43,11 @@ class RandomDeviceSeedSeq { } // namespace std::mt19937_64* GetSharedRng() { - static auto* rng = [] { + static absl::NoDestructor<std::mt19937_64> rng([] { RandomDeviceSeedSeq seed_seq; - return new std::mt19937_64(seed_seq); - }(); - return rng; + return std::mt19937_64(seed_seq); + }()); + return rng.get(); } std::string Generator<std::string>::operator()() const { @@ -59,7 +61,7 @@ std::string Generator<std::string>::operator()() const { } absl::string_view Generator<absl::string_view>::operator()() const { - static auto* arena = new std::deque<std::string>(); + static absl::NoDestructor<std::deque<std::string>> arena; // NOLINTNEXTLINE(runtime/int) std::uniform_int_distribution<short> chars(0x20, 0x7E); arena->emplace_back(); 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 { |