Skip to content

Commit

Permalink
Fix issue with my previous change
Browse files Browse the repository at this point in the history
(memory not deleted for node_hash_set/map.
  • Loading branch information
greg7mdp committed Sep 4, 2023
1 parent d464cbc commit 7df85b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions include/gtl/phmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,8 +1532,9 @@ class raw_hash_set
if (empty())
return;
if (capacity_) {
if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value) {
// not trivially destructible... we need to iterate and destroy values one by one
if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||
std::is_same<typename Policy::is_flat, std::false_type>::value) {
// node map or not trivially destructible... we need to iterate and destroy values one by one
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
Expand Down Expand Up @@ -2329,8 +2330,9 @@ class raw_hash_set
if (!capacity_)
return;

if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value) {
// not trivially destructible... we need to iterate and destroy values one by one
if constexpr (!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||
std::is_same<typename Policy::is_flat, std::false_type>::value) {
// node map or not trivially destructible... we need to iterate and destroy values one by one
for (size_t i = 0; i != capacity_; ++i) {
if (IsFull(ctrl_[i])) {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
Expand Down Expand Up @@ -4981,6 +4983,7 @@ struct FlatHashSetPolicy
using key_type = T;
using init_type = T;
using constant_iterators = std::true_type;
using is_flat = std::true_type;

template<class Allocator, class... Args>
static void construct(Allocator* alloc, slot_type* slot, Args&&... args)
Expand Down Expand Up @@ -5022,6 +5025,7 @@ struct FlatHashMapPolicy
using key_type = K;
using mapped_type = V;
using init_type = std::pair</*non const*/ key_type, mapped_type>;
using is_flat = std::true_type;

template<class Allocator, class... Args>
static void construct(Allocator* alloc, slot_type* slot, Args&&... args)
Expand Down Expand Up @@ -5110,6 +5114,7 @@ struct NodeHashSetPolicy : gtl::priv::node_hash_policy<T&, NodeHashSetPolicy<T>>
using key_type = T;
using init_type = T;
using constant_iterators = std::true_type;
using is_flat = std::false_type;

template<class Allocator, class... Args>
static T* new_element(Allocator* alloc, Args&&... args)
Expand Down Expand Up @@ -5151,6 +5156,7 @@ class NodeHashMapPolicy
using key_type = Key;
using mapped_type = Value;
using init_type = std::pair</*non const*/ key_type, mapped_type>;
using is_flat = std::false_type;

template<class Allocator, class... Args>
static value_type* new_element(Allocator* alloc, Args&&... args)
Expand Down
1 change: 1 addition & 0 deletions tests/phmap/raw_hash_set_allocator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct Policy
using slot_type = Tracked<int32_t>;
using init_type = Tracked<int32_t>;
using key_type = int32_t;
using is_flat = std::false_type;

template<class allocator_type, class... Args>
static void construct(allocator_type* alloc, slot_type* slot, Args&&... args)
Expand Down
3 changes: 3 additions & 0 deletions tests/phmap/raw_hash_set_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ struct IntPolicy
using slot_type = int64_t;
using key_type = int64_t;
using init_type = int64_t;
using is_flat = std::false_type;

static void construct(void*, int64_t* slot, int64_t v) { *slot = v; }
static void destroy(void*, int64_t*) {}
Expand Down Expand Up @@ -325,6 +326,7 @@ class StringPolicy

using key_type = std::string;
using init_type = std::pair<std::string, std::string>;
using is_flat = std::false_type;

template<class allocator_type, class... Args>
static void construct(allocator_type* alloc, slot_type* slot, Args... args)
Expand Down Expand Up @@ -653,6 +655,7 @@ struct DecomposePolicy
using slot_type = DecomposeType;
using key_type = DecomposeType;
using init_type = DecomposeType;
using is_flat = std::false_type;

template<typename T>
static void construct(void*, DecomposeType* slot, T&& v)
Expand Down

0 comments on commit 7df85b5

Please sign in to comment.