diff mbox series

[C++] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684)

Message ID 20180305203103.GQ5867@tucnak
State New
Headers show
Series [C++] Small performance improvement for constexpr_call_hasher::equal (PR c++/84684) | expand

Commit Message

Jakub Jelinek March 5, 2018, 8:31 p.m. UTC
Hi!

This doesn't actually fix this PR (Marek is working on that), but
just something I've noticed while analyzing the PR.
We have the hashes saved in the structure (to speed up hash table
expansion), so it is a waste not to test those also in the equal hook,
by giving up cheaply in cases of hash table collisions.

Additionally, the method returns bool, so this patch uses true/false
instead of 1/0.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84684
	* constexpr.c (constexpr_call_hasher::equal): Return false if
	lhs->hash != rhs->hash.  Change return 1 to return true and
	return 0 to return false.


	Jakub

Comments

Jason Merrill March 5, 2018, 10:08 p.m. UTC | #1
OK.

On Mon, Mar 5, 2018 at 3:31 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> This doesn't actually fix this PR (Marek is working on that), but
> just something I've noticed while analyzing the PR.
> We have the hashes saved in the structure (to speed up hash table
> expansion), so it is a waste not to test those also in the equal hook,
> by giving up cheaply in cases of hash table collisions.
>
> Additionally, the method returns bool, so this patch uses true/false
> instead of 1/0.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-03-05  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/84684
>         * constexpr.c (constexpr_call_hasher::equal): Return false if
>         lhs->hash != rhs->hash.  Change return 1 to return true and
>         return 0 to return false.
>
> --- gcc/cp/constexpr.c.jj       2018-03-05 16:11:08.510165108 +0100
> +++ gcc/cp/constexpr.c  2018-03-05 16:14:06.130229884 +0100
> @@ -1033,9 +1033,11 @@ constexpr_call_hasher::equal (constexpr_
>    tree lhs_bindings;
>    tree rhs_bindings;
>    if (lhs == rhs)
> -    return 1;
> +    return true;
> +  if (lhs->hash != rhs->hash)
> +    return false;
>    if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
> -    return 0;
> +    return false;
>    lhs_bindings = lhs->bindings;
>    rhs_bindings = rhs->bindings;
>    while (lhs_bindings != NULL && rhs_bindings != NULL)
> @@ -1044,7 +1046,7 @@ constexpr_call_hasher::equal (constexpr_
>        tree rhs_arg = TREE_VALUE (rhs_bindings);
>        gcc_assert (TREE_TYPE (lhs_arg) == TREE_TYPE (rhs_arg));
>        if (!cp_tree_equal (lhs_arg, rhs_arg))
> -        return 0;
> +        return false;
>        lhs_bindings = TREE_CHAIN (lhs_bindings);
>        rhs_bindings = TREE_CHAIN (rhs_bindings);
>      }
>
>         Jakub
diff mbox series

Patch

--- gcc/cp/constexpr.c.jj	2018-03-05 16:11:08.510165108 +0100
+++ gcc/cp/constexpr.c	2018-03-05 16:14:06.130229884 +0100
@@ -1033,9 +1033,11 @@  constexpr_call_hasher::equal (constexpr_
   tree lhs_bindings;
   tree rhs_bindings;
   if (lhs == rhs)
-    return 1;
+    return true;
+  if (lhs->hash != rhs->hash)
+    return false;
   if (!constexpr_fundef_hasher::equal (lhs->fundef, rhs->fundef))
-    return 0;
+    return false;
   lhs_bindings = lhs->bindings;
   rhs_bindings = rhs->bindings;
   while (lhs_bindings != NULL && rhs_bindings != NULL)
@@ -1044,7 +1046,7 @@  constexpr_call_hasher::equal (constexpr_
       tree rhs_arg = TREE_VALUE (rhs_bindings);
       gcc_assert (TREE_TYPE (lhs_arg) == TREE_TYPE (rhs_arg));
       if (!cp_tree_equal (lhs_arg, rhs_arg))
-        return 0;
+        return false;
       lhs_bindings = TREE_CHAIN (lhs_bindings);
       rhs_bindings = TREE_CHAIN (rhs_bindings);
     }