diff mbox series

[ovs-dev,2/3] Use and reuse hash wherever possible in shash

Message ID 20200731092323.763-3-anton.ivanov@cambridgegreys.com
State New
Headers show
Series [ovs-dev,1/3] Optimise shash disposal | expand

Commit Message

Anton Ivanov July 31, 2020, 9:23 a.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

Add missing hash uses into shash to avoid hash recomputations.

Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
 lib/shash.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

0-day Robot July 31, 2020, 10:01 a.m. UTC | #1
Bleep bloop.  Greetings Anton Ivanov, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line is 80 characters long (recommended limit is 79)
#34 FILE: lib/shash.c:347:
        if (!shash_find__(b, node->name, strlen(node->name), node->node.hash)) {

Lines checked: 40, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
Dumitru Ceara Aug. 7, 2020, 11:17 a.m. UTC | #2
On 7/31/20 11:23 AM, anton.ivanov@cambridgegreys.com wrote:
> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> 
> Add missing hash uses into shash to avoid hash recomputations.
> 
> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> ---
>  lib/shash.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/shash.c b/lib/shash.c
> index 09505b73d..f378d1656 100644
> --- a/lib/shash.c
> +++ b/lib/shash.c
> @@ -158,8 +158,9 @@ shash_add(struct shash *sh, const char *name, const void *data)
>  bool
>  shash_add_once(struct shash *sh, const char *name, const void *data)
>  {
> -    if (!shash_find(sh, name)) {
> -        shash_add(sh, name, data);
> +    size_t hash = hash_name(name);
> +    if (!shash_find__(sh, name, strlen(name), hash)) {
> +        shash_add_nocopy__(sh, xstrdup(name), data, hash);
>          return true;
>      } else {
>          return false;
> @@ -343,7 +344,7 @@ shash_equal_keys(const struct shash *a, const struct shash *b)
>          return false;
>      }
>      SHASH_FOR_EACH (node, a) {
> -        if (!shash_find(b, node->name)) {
> +        if (!shash_find__(b, node->name, strlen(node->name), node->node.hash)) {
>              return false;
>          }
>      }
> 

With the warning from 0-day robot above the line length addressed, this
patch looks good to me, thanks!

Acked-by: Dumitru Ceara <dceara@redhat.com>
diff mbox series

Patch

diff --git a/lib/shash.c b/lib/shash.c
index 09505b73d..f378d1656 100644
--- a/lib/shash.c
+++ b/lib/shash.c
@@ -158,8 +158,9 @@  shash_add(struct shash *sh, const char *name, const void *data)
 bool
 shash_add_once(struct shash *sh, const char *name, const void *data)
 {
-    if (!shash_find(sh, name)) {
-        shash_add(sh, name, data);
+    size_t hash = hash_name(name);
+    if (!shash_find__(sh, name, strlen(name), hash)) {
+        shash_add_nocopy__(sh, xstrdup(name), data, hash);
         return true;
     } else {
         return false;
@@ -343,7 +344,7 @@  shash_equal_keys(const struct shash *a, const struct shash *b)
         return false;
     }
     SHASH_FOR_EACH (node, a) {
-        if (!shash_find(b, node->name)) {
+        if (!shash_find__(b, node->name, strlen(node->name), node->node.hash)) {
             return false;
         }
     }