]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Make it possible for the hash value to point to the statically stored
authorBruno Haible <bruno@clisp.org>
Fri, 7 Oct 2005 11:29:05 +0000 (11:29 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:53 +0000 (12:12 +0200)
hash key.

gettext-tools/lib/ChangeLog
gettext-tools/lib/hash.c
gettext-tools/lib/hash.h
gettext-tools/src/ChangeLog
gettext-tools/src/message.c

index dd0f192622368eb5226806f4b8e03c98006d54fc..a3b2782aed5617376853f8d8c16290a62cc74d53 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-03  Bruno Haible  <bruno@clisp.org>
+
+       * hash.h (hash_insert_entry): Return a pointer instead of int.
+       * hash.c (hash_insert_entry): Return a pointer to the copy of the key.
+
 2005-10-03  Bruno Haible  <bruno@clisp.org>
 
        * hash.h: Add comments everywhere.
index 2a962103ebe7e0797e9bb6b82564d909d5ecb11f..21374f25f86cfd139af39c97358b8a166ab98e18 100644 (file)
@@ -262,9 +262,10 @@ resize (hash_table *htab)
 
 
 /* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
-   Return 0 if successful, or -1 if there is already an entry with the given
-   key.  */
-int
+   Return non-NULL (more precisely, the address of the KEY inside the table's
+   memory pool) if successful, or NULL if there is already an entry with the
+   given key.  */
+const void *
 hash_insert_entry (hash_table *htab,
                   const void *key, size_t keylen,
                   void *data)
@@ -275,7 +276,7 @@ hash_insert_entry (hash_table *htab,
 
   if (table[idx].used)
     /* We don't want to overwrite the old value.  */
-    return -1;
+    return NULL;
   else
     {
       /* An empty bucket has been found.  */
@@ -284,7 +285,7 @@ hash_insert_entry (hash_table *htab,
       if (100 * htab->filled > 75 * htab->size)
        /* Table is filled more than 75%.  Resize the table.  */
        resize (htab);
-      return 0;
+      return keycopy;
     }
 }
 
index 2e6ea52fae88221176e17b65bb458eee486fd4db..e4653e52589f81656a4a3ac4522130b4556354cc 100644 (file)
@@ -50,11 +50,12 @@ extern int hash_find_entry (hash_table *htab,
                            void **result);
 
 /* Try to insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
-   Return 0 if successful, or -1 if there is already an entry with the given
-   key.  */
-extern int hash_insert_entry (hash_table *htab,
-                             const void *key, size_t keylen,
-                             void *data);
+   Return non-NULL (more precisely, the address of the KEY inside the table's
+   memory pool) if successful, or NULL if there is already an entry with the
+   given key.  */
+extern const void * hash_insert_entry (hash_table *htab,
+                                      const void *key, size_t keylen,
+                                      void *data);
 
 /* Insert the pair (KEY[0..KEYLEN-1], DATA) in the hash table.
    Return 0.  */
index 5ae64f6cdf53769d6daa53404edf5115bd846fc9..bb13df5613f1d1615a332434c75f7c975bdb0092 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-03  Bruno Haible  <bruno@clisp.org>
+
+       * message.c (message_list_hash_insert_entry): Update.
+
 2005-10-03  Bruno Haible  <bruno@clisp.org>
 
        * message.c (message_list_alloc, message_list_free,
index b2b30108a8c865a6079fc61f3673029bf230dedd..0918e9f06f70677ca44275493390de89598219b8 100644 (file)
@@ -276,7 +276,7 @@ message_list_hash_insert_entry (hash_table *htable, message_ty *mp)
       keylen = strlen (mp->msgid) + 1;
     }
 
-  found = hash_insert_entry (htable, key, keylen, mp);
+  found = (hash_insert_entry (htable, key, keylen, mp) == NULL);
 
   if (mp->msgctxt != NULL)
     freesa (alloced_key);