From 36a3a7a3726c8b65eeceb6eb4a8946e0cd5650a9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 21 Mar 2019 23:00:04 +0100 Subject: hash-table.h (hash_table): Add Lazy template parameter defaulted to false... * hash-table.h (hash_table): Add Lazy template parameter defaulted to false, if true, don't alloc_entries during construction, but defer it to the first method that needs m_entries allocated. (hash_table::hash_table, hash_table::~hash_table, hash_table::alloc_entries, hash_table::find_empty_slot_for_expand, hash_table::too_empty_p, hash_table::expand, hash_table::empty_slow, hash_table::clear_slot, hash_table::traverse_noresize, hash_table::traverse, hash_table::iterator::slide): Adjust all methods. * hash-set.h (hash_set): Add Lazy template parameter defaulted to false. (hash_set::contains): If Lazy is true, use find_slot_with_hash with NO_INSERT instead of find_with_hash. (hash_set::traverse, hash_set::iterator, hash_set::iterator::m_iter, hash_set::m_table): Add Lazy to template params of hash_table. (gt_ggc_mx, gt_pch_nx): Use false as Lazy in hash_set template param. * attribs.c (test_attribute_exclusions): Likewise. * hash-set-tests.c (test_set_of_strings): Add iterator tests for hash_set. Add tests for hash_set with Lazy = true. c-family/ * c-common.c (per_file_includes_t): Use false as Lazy in hash_set template param. jit/ * jit-recording.c (reproducer::m_set_identifiers): Use false as Lazy in hash_set template param. From-SVN: r269859 --- gcc/hash-set.h | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'gcc/hash-set.h') diff --git a/gcc/hash-set.h b/gcc/hash-set.h index 1f09518..8e1f38b 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -21,7 +21,8 @@ along with GCC; see the file COPYING3. If not see #ifndef hash_set_h #define hash_set_h -template > +template > class hash_set { public: @@ -32,12 +33,12 @@ public: /* Create a hash_set in gc memory with space for at least n elements. */ static hash_set * - create_ggc (size_t n) - { - hash_set *set = ggc_alloc (); - new (set) hash_set (n, true); - return set; - } + create_ggc (size_t n) + { + hash_set *set = ggc_alloc (); + new (set) hash_set (n, true); + return set; + } /* If key k isn't already in the map add it to the map, and return false. Otherwise return true. */ @@ -56,6 +57,9 @@ public: bool contains (const Key &k) { + if (Lazy) + return (m_table.find_slot_with_hash (k, Traits::hash (k), NO_INSERT) + != NULL); Key &e = m_table.find_with_hash (k, Traits::hash (k)); return !Traits::is_empty (e); } @@ -71,7 +75,7 @@ public: template void traverse (Arg a) const { - for (typename hash_table::iterator iter = m_table.begin (); + for (typename hash_table::iterator iter = m_table.begin (); iter != m_table.end (); ++iter) f (*iter, a); } @@ -87,7 +91,8 @@ public: class iterator { public: - explicit iterator (const typename hash_table::iterator &iter) : + explicit iterator (const typename hash_table::iterator &iter) : m_iter (iter) {} iterator &operator++ () @@ -109,7 +114,7 @@ public: } private: - typename hash_table::iterator m_iter; + typename hash_table::iterator m_iter; }; /* Standard iterator retrieval methods. */ @@ -120,11 +125,14 @@ public: private: - template friend void gt_ggc_mx (hash_set *); - template friend void gt_pch_nx (hash_set *); - template friend void gt_pch_nx (hash_set *, gt_pointer_operator, void *); + template + friend void gt_ggc_mx (hash_set *); + template + friend void gt_pch_nx (hash_set *); + template + friend void gt_pch_nx (hash_set *, gt_pointer_operator, void *); - hash_table m_table; + hash_table m_table; }; /* Generic hash_set debug helper. @@ -169,21 +177,21 @@ debug_helper (hash_set &ref) template static inline void -gt_ggc_mx (hash_set *h) +gt_ggc_mx (hash_set *h) { gt_ggc_mx (&h->m_table); } template static inline void -gt_pch_nx (hash_set *h) +gt_pch_nx (hash_set *h) { gt_pch_nx (&h->m_table); } template static inline void -gt_pch_nx (hash_set *h, gt_pointer_operator op, void *cookie) +gt_pch_nx (hash_set *h, gt_pointer_operator op, void *cookie) { op (&h->m_table.m_entries, cookie); } -- cgit v1.1