public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/ppalka/heads/wip)] c++: Don't hash twice in satisfaction cache
@ 2020-11-02 21:31 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2020-11-02 21:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2a1088d4254e64448fa4eec4ec7db6c7f7962b30

commit 2a1088d4254e64448fa4eec4ec7db6c7f7962b30
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Nov 2 15:07:18 2020 -0500

    c++: Don't hash twice in satisfaction cache
    
    gcc/cp/ChangeLog:
    
            * constraint.cc (get_satisfaction):
            (save_satisfaction):
            (struct satisfaction_cache):

Diff:
---
 gcc/cp/constraint.cc | 50 ++++++++++++++++++--------------------------------
 1 file changed, 18 insertions(+), 32 deletions(-)

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 03a9afa2ef5..5866387fbe3 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2343,56 +2343,42 @@ struct sat_hasher : ggc_ptr_hash<sat_entry>
 /* Cache the result of satisfy_atom.  */
 static GTY((deletable)) hash_table<sat_hasher> *sat_cache;
 
-static tree
-get_satisfaction (tree constr, tree args)
-{
-  if (!sat_cache)
-    return NULL_TREE;
-  sat_entry elt = { constr, args, NULL_TREE };
-  sat_entry* found = sat_cache->find (&elt);
-  if (found)
-    return found->result;
-  else
-    return NULL_TREE;
-}
-
-static void
-save_satisfaction (tree constr, tree args, tree result)
-{
-  if (!sat_cache)
-    sat_cache = hash_table<sat_hasher>::create_ggc (31);
-  sat_entry elt = {constr, args, result};
-  sat_entry** slot = sat_cache->find_slot (&elt, INSERT);
-  sat_entry* entry = ggc_alloc<sat_entry> ();
-  *entry = elt;
-  *slot = entry;
-}
-
 /* A tool to help manage satisfaction caching in satisfy_constraint_r.
    Note the cache is only used when not diagnosing errors.  */
 
 struct satisfaction_cache
 {
   satisfaction_cache (tree constr, tree args, tsubst_flags_t complain)
-    : constr(constr), args(args), complain(complain)
-  { }
+    : complain(complain)
+  {
+    elt = {constr, args, NULL_TREE};
+    hash = sat_hasher::hash (&elt);
+  }
 
   tree get ()
   {
-    if (complain == tf_none)
-      return get_satisfaction (constr, args);
+    if (complain == tf_none && sat_cache)
+      if (sat_entry *found = sat_cache->find_with_hash (&elt, hash))
+	return found->result;
     return NULL_TREE;
   }
 
   tree save (tree result)
   {
     if (complain == tf_none)
-      save_satisfaction (constr, args, result);
+      {
+	if (!sat_cache)
+	  sat_cache = hash_table<sat_hasher>::create_ggc (31);
+	sat_entry **slot = sat_cache->find_slot_with_hash (&elt, hash, INSERT);
+	*slot = ggc_alloc<sat_entry> ();
+	**slot = elt;
+	(*slot)->result = result;
+      }
     return result;
   }
 
-  tree constr;
-  tree args;
+  sat_entry elt;
+  hashval_t hash;
   tsubst_flags_t complain;
 };


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-02 21:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 21:31 [gcc(refs/users/ppalka/heads/wip)] c++: Don't hash twice in satisfaction cache Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).