Commit 7bb3fbbb by Roger Sayle Committed by Roger Sayle

* tree.h (get_identifier) Define a macro form of get_identifier

	that calls get_identifier_with_length when the string is constant.
	(get_identifier_with_length): Change type of second argument to
	size_t in prototype.
	* stringpool.c (get_identifier): Undefine the macro before giving
	the function definition.
	(get_identifier_with_length): Change  type of second argument to
	size_t in function definition.
	* hashtable.c (calc_hash): Change type of second argument to size_t.
  	(ht_lookup): Change type of third argument to size_t.  Reorganize
	to speed-up the cases where the hash table slot is empty, or the
	first probe matches (i.e. there isn't a collision).
	* hashtable.h (ht_lookup): Adjust function prototype.

From-SVN: r70256
parent 32247ce9
2003-08-08 Roger Sayle <roger@eyesopen.com>
* tree.h (get_identifier) Define a macro form of get_identifier
that calls get_identifier_with_length when the string is constant.
(get_identifier_with_length): Change type of second argument to
size_t in prototype.
* stringpool.c (get_identifier): Undefine the macro before giving
the function definition.
(get_identifier_with_length): Change type of second argument to
size_t in function definition.
* hashtable.c (calc_hash): Change type of second argument to size_t.
(ht_lookup): Change type of third argument to size_t. Reorganize
to speed-up the cases where the hash table slot is empty, or the
first probe matches (i.e. there isn't a collision).
* hashtable.h (ht_lookup): Adjust function prototype.
2003-08-08 Bernardo Innocenti <bernie@develer.com> 2003-08-08 Bernardo Innocenti <bernie@develer.com>
PR target/9697 PR target/9697
......
...@@ -30,16 +30,16 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -30,16 +30,16 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
existing entry with a potential new one. Also, the ability to existing entry with a potential new one. Also, the ability to
delete members from the table has been removed. */ delete members from the table has been removed. */
static unsigned int calc_hash (const unsigned char *, unsigned int); static unsigned int calc_hash (const unsigned char *, size_t);
static void ht_expand (hash_table *); static void ht_expand (hash_table *);
static double approx_sqrt (double); static double approx_sqrt (double);
/* Calculate the hash of the string STR of length LEN. */ /* Calculate the hash of the string STR of length LEN. */
static unsigned int static unsigned int
calc_hash (const unsigned char *str, unsigned int len) calc_hash (const unsigned char *str, size_t len)
{ {
unsigned int n = len; size_t n = len;
unsigned int r = 0; unsigned int r = 0;
#define HASHSTEP(r, c) ((r) * 67 + ((c) - 113)); #define HASHSTEP(r, c) ((r) * 67 + ((c) - 113));
...@@ -92,7 +92,7 @@ ht_destroy (hash_table *table) ...@@ -92,7 +92,7 @@ ht_destroy (hash_table *table)
CPP_ALLOCED and the item is assumed to be at the top of the CPP_ALLOCED and the item is assumed to be at the top of the
obstack. */ obstack. */
hashnode hashnode
ht_lookup (hash_table *table, const unsigned char *str, unsigned int len, ht_lookup (hash_table *table, const unsigned char *str, size_t len,
enum ht_lookup_option insert) enum ht_lookup_option insert)
{ {
unsigned int hash = calc_hash (str, len); unsigned int hash = calc_hash (str, len);
...@@ -103,21 +103,15 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len, ...@@ -103,21 +103,15 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len,
sizemask = table->nslots - 1; sizemask = table->nslots - 1;
index = hash & sizemask; index = hash & sizemask;
/* hash2 must be odd, so we're guaranteed to visit every possible
location in the table during rehashing. */
hash2 = ((hash * 17) & sizemask) | 1;
table->searches++; table->searches++;
for (;;) node = table->entries[index];
if (node != NULL)
{ {
node = table->entries[index]; if (node->hash_value == hash
&& HT_LEN (node) == (unsigned int) len
if (node == NULL) && !memcmp (HT_STR (node), str, len))
break;
if (node->hash_value == hash && HT_LEN (node) == len
&& !memcmp (HT_STR (node), str, len))
{ {
if (insert == HT_ALLOCED) if (insert == HT_ALLOCED)
/* The string we search for was placed at the end of the /* The string we search for was placed at the end of the
...@@ -126,8 +120,29 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len, ...@@ -126,8 +120,29 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len,
return node; return node;
} }
index = (index + hash2) & sizemask; /* hash2 must be odd, so we're guaranteed to visit every possible
table->collisions++; location in the table during rehashing. */
hash2 = ((hash * 17) & sizemask) | 1;
for (;;)
{
table->collisions++;
index = (index + hash2) & sizemask;
node = table->entries[index];
if (node == NULL)
break;
if (node->hash_value == hash
&& HT_LEN (node) == (unsigned int) len
&& !memcmp (HT_STR (node), str, len))
{
if (insert == HT_ALLOCED)
/* The string we search for was placed at the end of the
obstack. Release it. */
obstack_free (&table->stack, (void *) str);
return node;
}
}
} }
if (insert == HT_NO_INSERT) if (insert == HT_NO_INSERT)
...@@ -136,7 +151,7 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len, ...@@ -136,7 +151,7 @@ ht_lookup (hash_table *table, const unsigned char *str, unsigned int len,
node = (*table->alloc_node) (table); node = (*table->alloc_node) (table);
table->entries[index] = node; table->entries[index] = node;
HT_LEN (node) = len; HT_LEN (node) = (unsigned int) len;
node->hash_value = hash; node->hash_value = hash;
if (insert == HT_ALLOC) if (insert == HT_ALLOC)
HT_STR (node) = obstack_copy0 (&table->stack, str, len); HT_STR (node) = obstack_copy0 (&table->stack, str, len);
......
...@@ -67,7 +67,7 @@ extern hash_table *ht_create (unsigned int order); ...@@ -67,7 +67,7 @@ extern hash_table *ht_create (unsigned int order);
extern void ht_destroy (hash_table *); extern void ht_destroy (hash_table *);
extern hashnode ht_lookup (hash_table *, const unsigned char *, extern hashnode ht_lookup (hash_table *, const unsigned char *,
unsigned int, enum ht_lookup_option); size_t, enum ht_lookup_option);
/* For all nodes in TABLE, make a callback. The callback takes /* For all nodes in TABLE, make a callback. The callback takes
TABLE->PFILE, the node, and a PTR, and the callback sequence stops TABLE->PFILE, the node, and a PTR, and the callback sequence stops
......
...@@ -95,6 +95,8 @@ ggc_alloc_string (const char *contents, int length) ...@@ -95,6 +95,8 @@ ggc_alloc_string (const char *contents, int length)
If an identifier with that name has previously been referred to, If an identifier with that name has previously been referred to,
the same node is returned this time. */ the same node is returned this time. */
#undef get_identifier
tree tree
get_identifier (const char *text) get_identifier (const char *text)
{ {
...@@ -110,7 +112,7 @@ get_identifier (const char *text) ...@@ -110,7 +112,7 @@ get_identifier (const char *text)
known. */ known. */
tree tree
get_identifier_with_length (const char *text, unsigned int length) get_identifier_with_length (const char *text, size_t length)
{ {
hashnode ht_node = ht_lookup (ident_hash, hashnode ht_node = ht_lookup (ident_hash,
(const unsigned char *) text, (const unsigned char *) text,
......
...@@ -2050,10 +2050,18 @@ extern tree make_tree_vec (int); ...@@ -2050,10 +2050,18 @@ extern tree make_tree_vec (int);
extern tree get_identifier (const char *); extern tree get_identifier (const char *);
#if GCC_VERSION >= 3000
#define get_identifier(str) \
(__builtin_constant_p (str) \
? get_identifier_with_length ((str), strlen (str)) \
: get_identifier (str))
#endif
/* Identical to get_identifier, except that the length is assumed /* Identical to get_identifier, except that the length is assumed
known. */ known. */
extern tree get_identifier_with_length (const char *, unsigned int); extern tree get_identifier_with_length (const char *, size_t);
/* If an identifier with the name TEXT (a null-terminated string) has /* If an identifier with the name TEXT (a null-terminated string) has
previously been referred to, return that node; otherwise return previously been referred to, return that node; otherwise return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment