changeset 2586:7fe4d4dbfbff

Ignoring previous value in njs_flathsh_insert(). Previously, fhq->value was set to a previous value if the value existed. This is not used anymore in the code.
author Vadim Zhestikov <v.zhestikov@f5.com>
date Thu, 12 Jun 2025 08:34:17 -0700
parents 6c9f4bb88e0c
children de3d0a24ee1b
files src/njs_flathsh.c src/njs_flathsh.h
diffstat 2 files changed, 7 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/njs_flathsh.c	Wed Jun 25 11:50:25 2025 -0700
+++ b/src/njs_flathsh.c	Thu Jun 12 08:34:17 2025 -0700
@@ -376,7 +376,6 @@
 njs_int_t
 njs_flathsh_insert(njs_flathsh_t *fh, njs_flathsh_query_t *fhq)
 {
-    void                 *tmp;
     njs_int_t            cell_num, elt_num;
     njs_flathsh_elt_t    *elt, *elts;
     njs_flathsh_descr_t  *h;
@@ -403,15 +402,11 @@
             fhq->proto->test(fhq, elt->value) == NJS_OK)
         {
             if (fhq->replace) {
-                tmp = fhq->value;
-                fhq->value = elt->value;
-                elt->value = tmp;
+                elt->value = fhq->value;
 
                 return NJS_OK;
 
             } else {
-                fhq->value = elt->value;
-
                 return NJS_DECLINED;
             }
         }
--- a/src/njs_flathsh.h	Wed Jun 25 11:50:25 2025 -0700
+++ b/src/njs_flathsh.h	Thu Jun 12 08:34:17 2025 -0700
@@ -91,14 +91,13 @@
     njs_flathsh_query_t *fhq);
 
 /*
- * njs_flathsh_insert() adds a hash element.  If the element is already
- * present in flathsh and the fhq->replace flag is zero, then fhq->value
- * is updated with the old element and NJS_DECLINED is returned.
- * If the element is already present in flathsh and the fhq->replace flag
- * is non-zero, then the old element is replaced with the new element.
- * fhq->value is updated with the old element, and NJS_OK is returned.
+ * njs_flathsh_insert() adds a hash element.  If the element is already present
+ * in flathsh and the fhq->replace flag is zero, then NJS_DECLINED is returned.
+ * If the element is already present in flathsh and the fhq->replace flag is
+ * non-zero, then the old element is replaced with the new element and NJS_OK is
+ * returned.
  * If the element is not present in flathsh, then it is inserted and
- * NJS_OK is returned.  The fhq->value is not changed.
+ * NJS_OK is returned.
  * On memory allocation failure NJS_ERROR is returned.
  *
  * The required njs_flathsh_query_t fields: key_hash, key, proto, replace,