summaryrefslogtreecommitdiff
path: root/mysys/hash.c
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-10-14 18:03:46 +0300
committerunknown <monty@mishka.local>2004-10-14 18:03:46 +0300
commit3307318917fb2995eaed4fa8530613cba08ea341 (patch)
treed6c50a4680a01729ce573d4c4f548366a8d2b530 /mysys/hash.c
parent84ad2489ec5c57a9a22f935c18835c731b3745c1 (diff)
downloadmariadb-git-3307318917fb2995eaed4fa8530613cba08ea341.tar.gz
true,false -> TRUE, FALSE
Simple fixes/optimization of things discovered during review of new pushed code include/my_sys.h: Ensure that clear_alloc_root() interacts correctly with alloc_root_inited() mysys/hash.c: More comments Simple optimization (merge identical code) mysys/my_bitmap.c: Change inline -> static inline sql/examples/ha_archive.cc: Fixed compiler warning sql/ha_ndbcluster.cc: true,false -> TRUE, FALSE Change if (false) -> #ifdef NOT_USED sql/ha_ndbcluster.h: true,false -> TRUE, FALSE sql/handler.cc: More comments Remove not needed initializations. #ifdef not used code sql/item_cmpfunc.h: true,false -> TRUE, FALSE sql/item_strfunc.cc: Move local variables to function beginning Remove wrong comments sql/log_event.h: true,false -> TRUE, FALSE sql/sql_base.cc: true,false -> TRUE, FALSE More comments sql/sql_help.cc: true,false -> TRUE, FALSE sql/sql_lex.cc: Simple optimization of new code sql/sql_parse.cc: true,false -> TRUE, FALSE sql/sql_prepare.cc: true,false -> TRUE, FALSE sql/sql_table.cc: true,false -> TRUE, FALSE sql/sql_yacc.yy: true,false -> TRUE, FALSE
Diffstat (limited to 'mysys/hash.c')
-rw-r--r--mysys/hash.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/mysys/hash.c b/mysys/hash.c
index 6f2788ddce7..1296a9289e9 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -72,19 +72,48 @@ _hash_init(HASH *hash,CHARSET_INFO *charset,
}
-void hash_free(HASH *hash)
+/*
+ Call hash->free on all elements in hash.
+
+ SYNOPSIS
+ hash_free_elements()
+ hash hash table
+
+ NOTES:
+ Sets records to 0
+*/
+
+static void inline hash_free_elements(HASH *hash)
{
- DBUG_ENTER("hash_free");
if (hash->free)
{
- uint i,records;
HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*);
- for (i=0,records=hash->records ; i < records ; i++)
- (*hash->free)(data[i].data);
- hash->free=0;
+ HASH_LINK *end= data + hash->records;
+ while (data < end)
+ (*hash->free)((data++)->data);
}
- delete_dynamic(&hash->array);
hash->records=0;
+}
+
+
+/*
+ Free memory used by hash.
+
+ SYNOPSIS
+ hash_free()
+ hash the hash to delete elements of
+
+ NOTES: Hash can't be reused wuthing calling hash_init again.
+*/
+
+void hash_free(HASH *hash)
+{
+ DBUG_ENTER("hash_free");
+ DBUG_PRINT("enter",("hash: 0x%lxd",hash));
+
+ hash_free_elements(hash);
+ hash->free= 0;
+ delete_dynamic(&hash->array);
DBUG_VOID_RETURN;
}
@@ -94,21 +123,17 @@ void hash_free(HASH *hash)
SYNOPSIS
hash_reset()
- hash the hash to delete elements of
+ hash the hash to delete elements of
*/
void hash_reset(HASH *hash)
{
DBUG_ENTER("hash_reset");
- if (hash->free)
- {
- HASH_LINK *link= dynamic_element(&hash->array, 0, HASH_LINK*);
- HASH_LINK *end= link + hash->records;
- for (; link < end; ++link)
- (*hash->free)(link->data);
- }
+ DBUG_PRINT("enter",("hash: 0x%lxd",hash));
+
+ hash_free_elements(hash);
reset_dynamic(&hash->array);
- hash->records= 0;
+ /* Set row pointers so that the hash can be reused at once */
hash->blength= 1;
hash->current_record= NO_RECORD;
DBUG_VOID_RETURN;