OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libcpp / symtab.c
index c80dfa2..ffa28f5 100644 (file)
@@ -13,7 +13,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
@@ -41,13 +41,11 @@ calc_hash (const unsigned char *str, size_t len)
 {
   size_t n = len;
   unsigned int r = 0;
-#define HASHSTEP(r, c) ((r) * 67 + ((c) - 113));
 
   while (n--)
-    r = HASHSTEP (r, *str++);
+    r = HT_HASHSTEP (r, *str++);
 
-  return r + len;
-#undef HASHSTEP
+  return HT_HASHFINISH (r, len);
 }
 
 /* Initialize an identifier hashtable.  */
@@ -58,7 +56,7 @@ ht_create (unsigned int order)
   unsigned int nslots = 1 << order;
   hash_table *table;
 
-  table = xcalloc (1, sizeof (hash_table));
+  table = XCNEW (hash_table);
 
   /* Strings need no alignment.  */
   _obstack_begin (&table->stack, 0, 0,
@@ -67,7 +65,7 @@ ht_create (unsigned int order)
 
   obstack_alignment_mask (&table->stack) = 0;
 
-  table->entries = xcalloc (nslots, sizeof (hashnode));
+  table->entries = XCNEWVEC (hashnode, nslots);
   table->entries_owned = true;
   table->nslots = nslots;
   return table;
@@ -96,7 +94,15 @@ hashnode
 ht_lookup (hash_table *table, const unsigned char *str, size_t len,
           enum ht_lookup_option insert)
 {
-  unsigned int hash = calc_hash (str, len);
+  return ht_lookup_with_hash (table, str, len, calc_hash (str, len),
+                             insert);
+}
+
+hashnode
+ht_lookup_with_hash (hash_table *table, const unsigned char *str,
+                    size_t len, unsigned int hash,
+                    enum ht_lookup_option insert)
+{
   unsigned int hash2;
   unsigned int index;
   size_t sizemask;
@@ -155,7 +161,8 @@ ht_lookup (hash_table *table, const unsigned char *str, size_t len,
   HT_LEN (node) = (unsigned int) len;
   node->hash_value = hash;
   if (insert == HT_ALLOC)
-    HT_STR (node) = obstack_copy0 (&table->stack, str, len);
+    HT_STR (node) = (const unsigned char *) obstack_copy0 (&table->stack,
+                                                           str, len);
   else
     HT_STR (node) = str;
 
@@ -175,7 +182,7 @@ ht_expand (hash_table *table)
   unsigned int size, sizemask;
 
   size = table->nslots * 2;
-  nentries = xcalloc (size, sizeof (hashnode));
+  nentries = XCNEWVEC (hashnode, size);
   sizemask = size - 1;
 
   p = table->entries;
@@ -246,8 +253,8 @@ void
 ht_dump_statistics (hash_table *table)
 {
   size_t nelts, nids, overhead, headers;
-  size_t total_bytes, longest, sum_of_squares;
-  double exp_len, exp_len2, exp2_len;
+  size_t total_bytes, longest;
+  double sum_of_squares, exp_len, exp_len2, exp2_len;
   hashnode *p, *limit;
 
 #define SCALE(x) ((unsigned long) ((x) < 1024*10 \
@@ -266,7 +273,7 @@ ht_dump_statistics (hash_table *table)
        size_t n = HT_LEN (*p);
 
        total_bytes += n;
-       sum_of_squares += n * n;
+       sum_of_squares += (double) n * n;
        if (n > longest)
          longest = n;
        nids++;