From: Bruno Haible Date: Fri, 7 Oct 2005 11:29:05 +0000 (+0000) Subject: Make it possible for the hash value to point to the statically stored X-Git-Tag: v0.15~375 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb0eac2f6599a31e25af1bc14b50f18f22b06103;p=thirdparty%2Fgettext.git Make it possible for the hash value to point to the statically stored hash key. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index dd0f19262..a3b2782ae 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,8 @@ +2005-10-03 Bruno Haible + + * 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 * hash.h: Add comments everywhere. diff --git a/gettext-tools/lib/hash.c b/gettext-tools/lib/hash.c index 2a962103e..21374f25f 100644 --- a/gettext-tools/lib/hash.c +++ b/gettext-tools/lib/hash.c @@ -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; } } diff --git a/gettext-tools/lib/hash.h b/gettext-tools/lib/hash.h index 2e6ea52fa..e4653e525 100644 --- a/gettext-tools/lib/hash.h +++ b/gettext-tools/lib/hash.h @@ -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. */ diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 5ae64f6cd..bb13df561 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,7 @@ +2005-10-03 Bruno Haible + + * message.c (message_list_hash_insert_entry): Update. + 2005-10-03 Bruno Haible * message.c (message_list_alloc, message_list_free, diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index b2b30108a..0918e9f06 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -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);