#include "config.h"
#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
#include "hashtable.h"
/* The code below is a specialization of Vladimir Makarov's expandable
static unsigned int calc_hash PARAMS ((const unsigned char *, unsigned int));
static void ht_expand PARAMS ((hash_table *));
-/* Let particular systems override the size of a chunk. */
-#ifndef OBSTACK_CHUNK_SIZE
-#define OBSTACK_CHUNK_SIZE 0
-#endif
- /* Let them override the alloc and free routines too. */
-#ifndef OBSTACK_CHUNK_ALLOC
-#define OBSTACK_CHUNK_ALLOC xmalloc
-#endif
-#ifndef OBSTACK_CHUNK_FREE
-#define OBSTACK_CHUNK_FREE free
-#endif
-
-/* Initialise an obstack. */
-void
-gcc_obstack_init (obstack)
- struct obstack *obstack;
-{
- _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
- (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
- (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
-}
-
/* Calculate the hash of the string STR of length LEN. */
static unsigned int
return table;
}
+/* Frees all memory associated with a hash table. */
+
+void
+ht_destroy (table)
+ hash_table *table;
+{
+ obstack_free (&table->stack, NULL);
+ free (table->entries);
+ free (table);
+}
+
/* Returns the hash entry for the a STR of length LEN. If that string
already exists in the table, returns the existing entry, and, if
INSERT is CPP_ALLOCED, frees the last obstack object. If the
if (node == NULL)
break;
- if (HT_LEN (node) == len && !memcmp (HT_STR (node), str, len))
+ if (node->hash_value == hash && HT_LEN (node) == len
+ && !memcmp (HT_STR (node), str, len))
{
if (insert == HT_ALLOCED)
/* The string we search for was placed at the end of the
table->entries[index] = node;
HT_LEN (node) = len;
+ node->hash_value = hash;
if (insert == HT_ALLOC)
- HT_STR (node) = obstack_copy (&table->stack, str, len + 1);
+ HT_STR (node) = obstack_copy0 (&table->stack, str, len);
else
HT_STR (node) = str;
{
unsigned int index, hash, hash2;
- hash = calc_hash (HT_STR (*p), HT_LEN (*p));
+ hash = (*p)->hash_value;
hash2 = ((hash * 17) & sizemask) | 1;
index = hash & sizemask;