Commit e38992e8 by Richard Kenner Committed by Richard Kenner

conflict.c (conflict_graph_add): Pass enum type to htab_find_slot.

	* gcc/conflict.c (conflict_graph_add): Pass enum type to
	htab_find_slot.
	* gcc/cpperror.c (hashtab.h): Now include.
	* gcc/cppexp.c (hashtab.h): Likewise.
	* gcc/cpplex.c (hashtab.h): Likewise.
	* gcc/cppfiles.c (hashtab.h): Likewise.
	(find_include_file, _cpp_calc_hash, cpp_read_file): Pass enum type
	to htab_find_slot_with_hash.
	* gcc/cpphash.c (hashtab.h): Now include.
	(_cpp_lookup_slot): INSERT is now enum insert_option.
	* gcc/cpphash.h (_cpp_lookup_slot): Likewise.
	* gcc/cppinit.c (hashtab.h): Include earlier.
	(initialize_builtins): Pass enum to htab_find_slot.
	* gcc/cpplib.c (hashtab.h): Now include.
	(do_define, do_undef): Pass enum type to _cpp_lookup_slot.
	(do_pragma_poison, do_assert): Likewise.
	* gcc/emit-rtl.c (gen_rtx_CONST_INT): Pass enum to
	htab_find_slot_with_hash.
	* gcc/simplify-rtx.c (cselib_lookup_mem, cselib_lookup): Likewise.
	* gcc/tree.c (type_hash_add): Likewise.
	(build1): Minor cleanup.
	* include/hashtab.h (enum insert_option): New type.
	(htab_find_slot, htab_find_slot_with_hash): Use it.
	* libiberty/hashtab.c: Various minor cleanups.
	(htab_find_slot_with_hash): INSERT is now enum insert_option.
	(htab_find_slot): Likewise.

From-SVN: r33236
parent 0d9eb3ba
Tue Apr 18 14:16:47 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* conflict.c (conflict_graph_add): Pass enum type to htab_find_slot.
* cpperror.c (hashtab.h): Now include.
* cppexp.c (hashtab.h): Likewise.
* cpplex.c (hashtab.h): Likewise.
* cppfiles.c (hashtab.h): Likewise.
(find_include_file, _cpp_calc_hash, cpp_read_file): Pass enum type
to htab_find_slot_with_hash.
* cpphash.c (hashtab.h): Now include.
(_cpp_lookup_slot): INSERT is now enum insert_option.
* cpphash.h (_cpp_lookup_slot): Likewise.
* cppinit.c (hashtab.h): Include earlier.
(initialize_builtins): Pass enum to htab_find_slot.
* cpplib.c (hashtab.h): Now include.
(do_define, do_undef): Pass enum type to _cpp_lookup_slot.
(do_pragma_poison, do_assert): Likewise.
* emit-rtl.c (gen_rtx_CONST_INT): Pass enum to
htab_find_slot_with_hash.
* simplify-rtx.c (cselib_lookup_mem, cselib_lookup): Likewise.
* tree.c (type_hash_add): Likewise.
(build1): Minor cleanup.
* ggc-common.c: Add missing blanks.
* print-tree.c (print_node): Print DECL_OFFSET_ALIGN.
* tree.h (DECL_OFFSET_ALIGN): Fix typo in comment.
* stmt.c (mark_case_node): New function.
(mark_case_nesting): Call it.
* expmed.c (emit_store_flag): If comparing two-word integer
with zero, can optimize NE, EQ, GE, and LT.
* c-decl.c (mark_binding_level): Use 'for' instead of `while'.
* conflict.c: Minor cleanups.
* optabs.c: Add blank line
* simplify-rtx.c: Minor cleanups.
2000-04-18 Stan Cox <scox@cygnus.com> 2000-04-18 Stan Cox <scox@cygnus.com>
* gengenrtl.c (genlegend): Fix misspelling. * gengenrtl.c (genlegend): Fix misspelling.
...@@ -20,23 +58,6 @@ ...@@ -20,23 +58,6 @@
(OLD_CC): Likewise. (OLD_CC): Likewise.
* config/m68k/x-ccur (X_CFLAGS): Likewise. * config/m68k/x-ccur (X_CFLAGS): Likewise.
Tue Apr 18 14:16:47 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* ggc-common.c: Add missing blanks.
* print-tree.c (print_node): Print DECL_OFFSET_ALIGN.
* tree.h (DECL_OFFSET_ALIGN): Fix typo in comment.
* stmt.c (mark_case_node): New function.
(mark_case_nesting): Call it.
* expmed.c (emit_store_flag): If comparing two-word integer
with zero, can optimize NE, EQ, GE, and LT.
* c-decl.c (mark_binding_level): Use 'for' instead of `while'.
* conflict.c: Minor cleanups.
* optabs.c: Add blank line
* simplify-rtx.c: Minor cleanups.
2000-04-18 Mark Mitchell <mark@codesourcery.com> 2000-04-18 Mark Mitchell <mark@codesourcery.com>
* cpplex.c (_cpp_lex_token): Don't call CPP_BUMP_LINE when the * cpplex.c (_cpp_lex_token): Don't call CPP_BUMP_LINE when the
......
...@@ -25,6 +25,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -25,6 +25,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "hashtab.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "intl.h" #include "intl.h"
......
/* Parse C expressions for cpplib. /* Parse C expressions for cpplib.
Copyright (C) 1987, 92, 94, 95, 97, 98, 1999, 2000 Free Software Foundation. Copyright (C) 1987, 92, 94, 95, 97, 98, 1999, 2000 Free Software Foundation.
Contributed by Per Bothner, 1994.
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the under the terms of the GNU General Public License as published by the
...@@ -14,19 +15,14 @@ GNU General Public License for more details. ...@@ -14,19 +15,14 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. Boston, MA 02111-1307, USA. */
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding!
Written by Per Bothner 1994. */
/* Parse a C expression from text in a string */ /* Parse a C expression from text in a string */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "cpplib.h" #include "cpplib.h"
#include "hashtab.h"
#include "cpphash.h" #include "cpphash.h"
#ifndef CHAR_TYPE_SIZE #ifndef CHAR_TYPE_SIZE
......
...@@ -18,17 +18,13 @@ GNU General Public License for more details. ...@@ -18,17 +18,13 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "hashtab.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "hashtab.h"
#include "intl.h" #include "intl.h"
#include "mkdeps.h" #include "mkdeps.h"
...@@ -263,8 +259,8 @@ find_include_file (pfile, fname, search_start, ihash, before) ...@@ -263,8 +259,8 @@ find_include_file (pfile, fname, search_start, ihash, before)
dummy.hash = _cpp_calc_hash (fname, strlen (fname)); dummy.hash = _cpp_calc_hash (fname, strlen (fname));
path = (fname[0] == '/') ? ABSOLUTE_PATH : search_start; path = (fname[0] == '/') ? ABSOLUTE_PATH : search_start;
slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
(const void *)&dummy, (const void *) &dummy,
dummy.hash, 1); dummy.hash, INSERT);
if (*slot && (ih = redundant_include_p (pfile, *slot, path))) if (*slot && (ih = redundant_include_p (pfile, *slot, path)))
{ {
...@@ -333,8 +329,8 @@ _cpp_fake_ihash (pfile, fname) ...@@ -333,8 +329,8 @@ _cpp_fake_ihash (pfile, fname)
dummy.nshort = fname; dummy.nshort = fname;
dummy.hash = _cpp_calc_hash (fname, strlen (fname)); dummy.hash = _cpp_calc_hash (fname, strlen (fname));
slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
(const void *)&dummy, (const void *) &dummy,
dummy.hash, 1); dummy.hash, INSERT);
if (*slot) if (*slot)
return (*slot)->name; return (*slot)->name;
ih = make_IHASH (fname, 0, ABSOLUTE_PATH, dummy.hash, slot); ih = make_IHASH (fname, 0, ABSOLUTE_PATH, dummy.hash, slot);
...@@ -670,10 +666,10 @@ cpp_read_file (pfile, fname) ...@@ -670,10 +666,10 @@ cpp_read_file (pfile, fname)
dummy.hash = _cpp_calc_hash (fname, strlen (fname)); dummy.hash = _cpp_calc_hash (fname, strlen (fname));
slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
(const void *) &dummy, (const void *) &dummy,
dummy.hash, 1); dummy.hash, INSERT);
if (*slot && (ih = redundant_include_p (pfile, *slot, ABSOLUTE_PATH))) if (*slot && (ih = redundant_include_p (pfile, *slot, ABSOLUTE_PATH)))
{ {
if (ih == (IHASH *)-1) if (ih == (IHASH *) -1)
return 1; /* Already included. */ return 1; /* Already included. */
} }
else else
......
...@@ -26,8 +26,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -26,8 +26,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h"
#include "hashtab.h" #include "hashtab.h"
#include "cpphash.h"
#undef abort #undef abort
static unsigned int hash_HASHNODE PARAMS ((const void *)); static unsigned int hash_HASHNODE PARAMS ((const void *));
...@@ -200,12 +201,13 @@ _cpp_lookup (pfile, name, len) ...@@ -200,12 +201,13 @@ _cpp_lookup (pfile, name, len)
} }
/* Find the hashtable slot for name "name". Used to insert or delete. */ /* Find the hashtable slot for name "name". Used to insert or delete. */
HASHNODE ** HASHNODE **
_cpp_lookup_slot (pfile, name, len, insert, hash) _cpp_lookup_slot (pfile, name, len, insert, hash)
cpp_reader *pfile; cpp_reader *pfile;
const U_CHAR *name; const U_CHAR *name;
int len; int len;
int insert; enum insert_option insert;
unsigned long *hash; unsigned long *hash;
{ {
const U_CHAR *bp; const U_CHAR *bp;
...@@ -214,7 +216,9 @@ _cpp_lookup_slot (pfile, name, len, insert, hash) ...@@ -214,7 +216,9 @@ _cpp_lookup_slot (pfile, name, len, insert, hash)
if (len < 0) if (len < 0)
{ {
for (bp = name; is_idchar (*bp); bp++); for (bp = name; is_idchar (*bp); bp++)
;
len = bp - name; len = bp - name;
} }
...@@ -223,7 +227,7 @@ _cpp_lookup_slot (pfile, name, len, insert, hash) ...@@ -223,7 +227,7 @@ _cpp_lookup_slot (pfile, name, len, insert, hash)
dummy.hash = _cpp_calc_hash (name, len); dummy.hash = _cpp_calc_hash (name, len);
slot = (HASHNODE **) htab_find_slot_with_hash (pfile->hashtab, slot = (HASHNODE **) htab_find_slot_with_hash (pfile->hashtab,
(void *)&dummy, (void *) &dummy,
dummy.hash, insert); dummy.hash, insert);
if (insert) if (insert)
*hash = dummy.hash; *hash = dummy.hash;
......
...@@ -274,7 +274,8 @@ extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t)); ...@@ -274,7 +274,8 @@ extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *, extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *,
const U_CHAR *, int)); const U_CHAR *, int));
extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *, extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *,
const U_CHAR *, int, int, const U_CHAR *, int,
enum insert_option,
unsigned long *)); unsigned long *));
extern void _cpp_free_definition PARAMS ((DEFINITION *)); extern void _cpp_free_definition PARAMS ((DEFINITION *));
extern DEFINITION *_cpp_create_definition PARAMS ((cpp_reader *, int)); extern DEFINITION *_cpp_create_definition PARAMS ((cpp_reader *, int));
......
...@@ -21,14 +21,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -21,14 +21,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "hashtab.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "output.h" #include "output.h"
#include "prefix.h" #include "prefix.h"
#include "intl.h" #include "intl.h"
#include "version.h" #include "version.h"
#include "hashtab.h"
#include "mkdeps.h" #include "mkdeps.h"
/* Predefined symbols, built-in macros, and the default include path. */ /* Predefined symbols, built-in macros, and the default include path. */
...@@ -683,7 +682,7 @@ initialize_builtins (pfile) ...@@ -683,7 +682,7 @@ initialize_builtins (pfile)
hp = _cpp_make_hashnode (b->name, len, b->type, hp = _cpp_make_hashnode (b->name, len, b->type,
_cpp_calc_hash (b->name, len)); _cpp_calc_hash (b->name, len));
hp->value.cpval = val; hp->value.cpval = val;
*(htab_find_slot (pfile->hashtab, (void *)hp, 1)) = hp; *(htab_find_slot (pfile->hashtab, (void *) hp, INSERT)) = hp;
if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output)) if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output))
dump_special_to_buffer (pfile, b->name); dump_special_to_buffer (pfile, b->name);
......
...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "intl.h" #include "intl.h"
#include "hashtab.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
......
...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "hashtab.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "hashtab.h" #include "hashtab.h"
...@@ -392,7 +393,7 @@ do_define (pfile) ...@@ -392,7 +393,7 @@ do_define (pfile)
goto out; goto out;
} }
slot = _cpp_lookup_slot (pfile, sym, len, 1, &hash); slot = _cpp_lookup_slot (pfile, sym, len, INSERT, &hash);
if (*slot) if (*slot)
{ {
int ok; int ok;
...@@ -770,7 +771,7 @@ do_undef (pfile) ...@@ -770,7 +771,7 @@ do_undef (pfile)
name = pfile->token_buffer + here; name = pfile->token_buffer + here;
CPP_SET_WRITTEN (pfile, here); CPP_SET_WRITTEN (pfile, here);
slot = _cpp_lookup_slot (pfile, name, len, 0, 0); slot = _cpp_lookup_slot (pfile, name, len, NO_INSERT, 0);
if (slot) if (slot)
{ {
HASHNODE *hp = *slot; HASHNODE *hp = *slot;
...@@ -1028,7 +1029,7 @@ do_pragma_poison (pfile) ...@@ -1028,7 +1029,7 @@ do_pragma_poison (pfile)
p = pfile->token_buffer + written; p = pfile->token_buffer + written;
len = strlen (p); len = strlen (p);
slot = _cpp_lookup_slot (pfile, p, len, 1, &hash); slot = _cpp_lookup_slot (pfile, p, len, INSERT, &hash);
if (*slot) if (*slot)
{ {
HASHNODE *hp = *slot; HASHNODE *hp = *slot;
...@@ -1586,14 +1587,14 @@ do_assert (pfile) ...@@ -1586,14 +1587,14 @@ do_assert (pfile)
sym = pfile->token_buffer + old_written; sym = pfile->token_buffer + old_written;
blen = (U_CHAR *) strchr (sym, '(') - sym; blen = (U_CHAR *) strchr (sym, '(') - sym;
tslot = _cpp_lookup_slot (pfile, sym, tlen, 1, &thash); tslot = _cpp_lookup_slot (pfile, sym, tlen, INSERT, &thash);
if (*tslot) if (*tslot)
{ {
cpp_warning (pfile, "%s re-asserted", sym); cpp_warning (pfile, "%s re-asserted", sym);
goto error; goto error;
} }
bslot = _cpp_lookup_slot (pfile, sym, blen, 1, &bhash); bslot = _cpp_lookup_slot (pfile, sym, blen, INSERT, &bhash);
if (! *bslot) if (! *bslot)
{ {
*bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash); *bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash);
......
...@@ -248,7 +248,8 @@ gen_rtx_CONST_INT (mode, arg) ...@@ -248,7 +248,8 @@ gen_rtx_CONST_INT (mode, arg)
#endif #endif
/* Look up the CONST_INT in the hash table. */ /* Look up the CONST_INT in the hash table. */
slot = htab_find_slot_with_hash (const_int_htab, &arg, (hashval_t) arg, 1); slot = htab_find_slot_with_hash (const_int_htab, &arg,
(hashval_t) arg, INSERT);
if (*slot == 0) if (*slot == 0)
{ {
if (!ggc_p) if (!ggc_p)
......
...@@ -2662,7 +2662,7 @@ cselib_lookup_mem (x, create) ...@@ -2662,7 +2662,7 @@ cselib_lookup_mem (x, create)
mem_elt = new_cselib_val (++next_unknown_value, GET_MODE (x)); mem_elt = new_cselib_val (++next_unknown_value, GET_MODE (x));
add_mem_for_addr (addr, mem_elt, x); add_mem_for_addr (addr, mem_elt, x);
slot = htab_find_slot_with_hash (hash_table, x, mem_elt->value, 1); slot = htab_find_slot_with_hash (hash_table, x, mem_elt->value, INSERT);
*slot = mem_elt; *slot = mem_elt;
return mem_elt; return mem_elt;
} }
...@@ -2782,7 +2782,7 @@ cselib_lookup (x, mode, create) ...@@ -2782,7 +2782,7 @@ cselib_lookup (x, mode, create)
e = new_cselib_val (++next_unknown_value, GET_MODE (x)); e = new_cselib_val (++next_unknown_value, GET_MODE (x));
e->locs = new_elt_loc_list (e->locs, x); e->locs = new_elt_loc_list (e->locs, x);
REG_VALUES (i) = new_elt_list (REG_VALUES (i), e); REG_VALUES (i) = new_elt_list (REG_VALUES (i), e);
slot = htab_find_slot_with_hash (hash_table, x, e->value, 1); slot = htab_find_slot_with_hash (hash_table, x, e->value, INSERT);
*slot = e; *slot = e;
return e; return e;
} }
...@@ -2795,7 +2795,8 @@ cselib_lookup (x, mode, create) ...@@ -2795,7 +2795,8 @@ cselib_lookup (x, mode, create)
if (! hashval) if (! hashval)
return 0; return 0;
slot = htab_find_slot_with_hash (hash_table, x, hashval, create); slot = htab_find_slot_with_hash (hash_table, x, hashval,
create ? INSERT : NO_INSERT);
if (slot == 0) if (slot == 0)
return 0; return 0;
......
Tue Apr 18 16:22:30 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* hashtab.h (enum insert_option): New type.
(htab_find_slot, htab_find_slot_with_hash): Use it.
2000-04-17 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2000-04-17 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* symcat.h: Honor autoconf macro HAVE_STRINGIZE. Add * symcat.h: Honor autoconf macro HAVE_STRINGIZE. Add
......
...@@ -102,6 +102,9 @@ struct htab ...@@ -102,6 +102,9 @@ struct htab
typedef struct htab *htab_t; typedef struct htab *htab_t;
/* An enum saying whether we insert into the hash table or not. */
enum insert_option {NO_INSERT, INSERT};
/* The prototypes of the package functions. */ /* The prototypes of the package functions. */
extern htab_t htab_create PARAMS ((size_t, htab_hash, extern htab_t htab_create PARAMS ((size_t, htab_hash,
...@@ -110,11 +113,13 @@ extern void htab_delete PARAMS ((htab_t)); ...@@ -110,11 +113,13 @@ extern void htab_delete PARAMS ((htab_t));
extern void htab_empty PARAMS ((htab_t)); extern void htab_empty PARAMS ((htab_t));
extern void *htab_find PARAMS ((htab_t, const void *)); extern void *htab_find PARAMS ((htab_t, const void *));
extern void **htab_find_slot PARAMS ((htab_t, const void *, int)); extern void **htab_find_slot PARAMS ((htab_t, const void *,
extern void *htab_find_with_hash PARAMS ((htab_t, const void *, enum insert_option));
hashval_t)); extern void *htab_find_with_hash PARAMS ((htab_t, const void *,
extern void **htab_find_slot_with_hash PARAMS ((htab_t, const void *, hashval_t));
hashval_t, int)); extern void **htab_find_slot_with_hash PARAMS ((htab_t, const void *,
hashval_t,
enum insert_option));
extern void htab_clear_slot PARAMS ((htab_t, void **)); extern void htab_clear_slot PARAMS ((htab_t, void **));
extern void htab_remove_elt PARAMS ((htab_t, void *)); extern void htab_remove_elt PARAMS ((htab_t, void *));
......
Tue Apr 18 16:23:31 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* hashtab.c: Various minor cleanups.
(htab_find_slot_with_hash): INSERT is now enum insert_option.
(htab_find_slot): Likewise.
2000-04-16 Dave Pitts <dpitts@cozx.com> 2000-04-16 Dave Pitts <dpitts@cozx.com>
* cplus-dem.c (cplus_demangle_opname): Changed to use islower. * cplus-dem.c (cplus_demangle_opname): Changed to use islower.
......
...@@ -58,7 +58,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -58,7 +58,7 @@ Boston, MA 02111-1307, USA. */
static unsigned long higher_prime_number PARAMS ((unsigned long)); static unsigned long higher_prime_number PARAMS ((unsigned long));
/* The following function returns the nearest prime number which is /* The following function returns the nearest prime number which is
greater than a given source number. */ greater than a given source number, N. */
static unsigned long static unsigned long
higher_prime_number (n) higher_prime_number (n)
...@@ -66,20 +66,24 @@ higher_prime_number (n) ...@@ -66,20 +66,24 @@ higher_prime_number (n)
{ {
unsigned long i; unsigned long i;
n |= 0x01; /* Force N to be odd. */ /* Ensure we have a larger number and then force to odd. */
n++;
n |= 0x01;
/* All odd numbers < 9 are prime. */
if (n < 9) if (n < 9)
return n; /* All odd numbers < 9 are prime. */ return n;
/* Otherwise find the next prime using a sieve. */
next: next:
n += 2;
i = 3; for (i = 3; i * i <= n; i += 2)
do if (n % i == 0)
{ {
if (n % i == 0) n += 2;
goto next; goto next;
i += 2; }
}
while ((i * i) <= n);
return n; return n;
} }
...@@ -116,13 +120,12 @@ htab_delete (htab) ...@@ -116,13 +120,12 @@ htab_delete (htab)
htab_t htab; htab_t htab;
{ {
int i; int i;
if (htab->del_f) if (htab->del_f)
for (i = htab->size - 1; i >= 0; i--) for (i = htab->size - 1; i >= 0; i--)
{ if (htab->entries[i] != EMPTY_ENTRY
if (htab->entries[i] != EMPTY_ENTRY && htab->entries[i] != DELETED_ENTRY)
&& htab->entries[i] != DELETED_ENTRY) (*htab->del_f) (htab->entries[i]);
(*htab->del_f) (htab->entries[i]);
}
free (htab->entries); free (htab->entries);
free (htab); free (htab);
...@@ -135,13 +138,12 @@ htab_empty (htab) ...@@ -135,13 +138,12 @@ htab_empty (htab)
htab_t htab; htab_t htab;
{ {
int i; int i;
if (htab->del_f) if (htab->del_f)
for (i = htab->size - 1; i >= 0; i--) for (i = htab->size - 1; i >= 0; i--)
{ if (htab->entries[i] != EMPTY_ENTRY
if (htab->entries[i] != EMPTY_ENTRY && htab->entries[i] != DELETED_ENTRY)
&& htab->entries[i] != DELETED_ENTRY) (*htab->del_f) (htab->entries[i]);
(*htab->del_f) (htab->entries[i]);
}
memset (htab->entries, 0, htab->size * sizeof (void *)); memset (htab->entries, 0, htab->size * sizeof (void *));
} }
...@@ -152,6 +154,7 @@ htab_empty (htab) ...@@ -152,6 +154,7 @@ htab_empty (htab)
hash table. hash table.
This function also assumes there are no deleted entries in the table. This function also assumes there are no deleted entries in the table.
HASH is the hash value for the element to be inserted. */ HASH is the hash value for the element to be inserted. */
static void ** static void **
find_empty_slot_for_expand (htab, hash) find_empty_slot_for_expand (htab, hash)
htab_t htab; htab_t htab;
...@@ -164,10 +167,10 @@ find_empty_slot_for_expand (htab, hash) ...@@ -164,10 +167,10 @@ find_empty_slot_for_expand (htab, hash)
for (;;) for (;;)
{ {
void **slot = htab->entries + index; void **slot = htab->entries + index;
if (*slot == EMPTY_ENTRY) if (*slot == EMPTY_ENTRY)
return slot; return slot;
else if (*slot == DELETED_ENTRY)
if (*slot == DELETED_ENTRY)
abort (); abort ();
index += hash2; index += hash2;
...@@ -203,14 +206,18 @@ htab_expand (htab) ...@@ -203,14 +206,18 @@ htab_expand (htab)
do do
{ {
void *x = *p; void *x = *p;
if (x != EMPTY_ENTRY && x != DELETED_ENTRY) if (x != EMPTY_ENTRY && x != DELETED_ENTRY)
{ {
void **q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x)); void **q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x));
*q = x; *q = x;
} }
p++; p++;
} }
while (p < olimit); while (p < olimit);
free (oentries); free (oentries);
} }
...@@ -255,6 +262,7 @@ htab_find_with_hash (htab, element, hash) ...@@ -255,6 +262,7 @@ htab_find_with_hash (htab, element, hash)
/* Like htab_find_slot_with_hash, but compute the hash value from the /* Like htab_find_slot_with_hash, but compute the hash value from the
element. */ element. */
void * void *
htab_find (htab, element) htab_find (htab, element)
htab_t htab; htab_t htab;
...@@ -274,14 +282,14 @@ htab_find_slot_with_hash (htab, element, hash, insert) ...@@ -274,14 +282,14 @@ htab_find_slot_with_hash (htab, element, hash, insert)
htab_t htab; htab_t htab;
const void *element; const void *element;
hashval_t hash; hashval_t hash;
int insert; enum insert_option insert;
{ {
void **first_deleted_slot; void **first_deleted_slot;
unsigned int index; unsigned int index;
hashval_t hash2; hashval_t hash2;
size_t size; size_t size;
if (insert && htab->size * 3 <= htab->n_elements * 4) if (insert == INSERT && htab->size * 3 <= htab->n_elements * 4)
htab_expand (htab); htab_expand (htab);
size = htab->size; size = htab->size;
...@@ -296,7 +304,7 @@ htab_find_slot_with_hash (htab, element, hash, insert) ...@@ -296,7 +304,7 @@ htab_find_slot_with_hash (htab, element, hash, insert)
void *entry = htab->entries[index]; void *entry = htab->entries[index];
if (entry == EMPTY_ENTRY) if (entry == EMPTY_ENTRY)
{ {
if (!insert) if (insert == NO_INSERT)
return NULL; return NULL;
htab->n_elements++; htab->n_elements++;
...@@ -315,11 +323,8 @@ htab_find_slot_with_hash (htab, element, hash, insert) ...@@ -315,11 +323,8 @@ htab_find_slot_with_hash (htab, element, hash, insert)
if (!first_deleted_slot) if (!first_deleted_slot)
first_deleted_slot = &htab->entries[index]; first_deleted_slot = &htab->entries[index];
} }
else else if ((*htab->eq_f) (entry, element))
{ return &htab->entries[index];
if ((*htab->eq_f) (entry, element))
return &htab->entries[index];
}
htab->collisions++; htab->collisions++;
index += hash2; index += hash2;
...@@ -330,11 +335,12 @@ htab_find_slot_with_hash (htab, element, hash, insert) ...@@ -330,11 +335,12 @@ htab_find_slot_with_hash (htab, element, hash, insert)
/* Like htab_find_slot_with_hash, but compute the hash value from the /* Like htab_find_slot_with_hash, but compute the hash value from the
element. */ element. */
void ** void **
htab_find_slot (htab, element, insert) htab_find_slot (htab, element, insert)
htab_t htab; htab_t htab;
const void *element; const void *element;
int insert; enum insert_option insert;
{ {
return htab_find_slot_with_hash (htab, element, (*htab->hash_f) (element), return htab_find_slot_with_hash (htab, element, (*htab->hash_f) (element),
insert); insert);
...@@ -351,7 +357,7 @@ htab_remove_elt (htab, element) ...@@ -351,7 +357,7 @@ htab_remove_elt (htab, element)
{ {
void **slot; void **slot;
slot = htab_find_slot (htab, element, 0); slot = htab_find_slot (htab, element, NO_INSERT);
if (*slot == EMPTY_ENTRY) if (*slot == EMPTY_ENTRY)
return; return;
...@@ -374,8 +380,10 @@ htab_clear_slot (htab, slot) ...@@ -374,8 +380,10 @@ htab_clear_slot (htab, slot)
if (slot < htab->entries || slot >= htab->entries + htab->size if (slot < htab->entries || slot >= htab->entries + htab->size
|| *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY) || *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY)
abort (); abort ();
if (htab->del_f) if (htab->del_f)
(*htab->del_f) (*slot); (*htab->del_f) (*slot);
*slot = DELETED_ENTRY; *slot = DELETED_ENTRY;
htab->n_deleted++; htab->n_deleted++;
} }
...@@ -391,12 +399,13 @@ htab_traverse (htab, callback, info) ...@@ -391,12 +399,13 @@ htab_traverse (htab, callback, info)
htab_trav callback; htab_trav callback;
void *info; void *info;
{ {
void **slot, **limit; void **slot = htab->entries;
slot = htab->entries; void **limit = slot + htab->size;
limit = slot + htab->size;
do do
{ {
void *x = *slot; void *x = *slot;
if (x != EMPTY_ENTRY && x != DELETED_ENTRY) if (x != EMPTY_ENTRY && x != DELETED_ENTRY)
if (!(*callback) (slot, info)) if (!(*callback) (slot, info))
break; break;
...@@ -404,7 +413,7 @@ htab_traverse (htab, callback, info) ...@@ -404,7 +413,7 @@ htab_traverse (htab, callback, info)
while (++slot < limit); while (++slot < limit);
} }
/* The following function returns current size of given hash table. */ /* Return the current size of given hash table. */
size_t size_t
htab_size (htab) htab_size (htab)
...@@ -413,8 +422,7 @@ htab_size (htab) ...@@ -413,8 +422,7 @@ htab_size (htab)
return htab->size; return htab->size;
} }
/* The following function returns current number of elements in given /* Return the current number of elements in given hash table. */
hash table. */
size_t size_t
htab_elements (htab) htab_elements (htab)
...@@ -423,17 +431,15 @@ htab_elements (htab) ...@@ -423,17 +431,15 @@ htab_elements (htab)
return htab->n_elements - htab->n_deleted; return htab->n_elements - htab->n_deleted;
} }
/* The following function returns number of percents of fixed /* Return the fraction of fixed collisions during all work with given
collisions during all work with given hash table. */ hash table. */
double double
htab_collisions (htab) htab_collisions (htab)
htab_t htab; htab_t htab;
{ {
int searches; if (htab->searches == 0)
searches = htab->searches;
if (searches == 0)
return 0.0; return 0.0;
return (double)htab->collisions / (double)searches;
return (double) htab->collisions / (double) htab->searches;
} }
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