Sync libiberty sources with GCC.
[deliverable/binutils-gdb.git] / libiberty / hashtab.c
index dfaec0f31aeef59dc0263ff1de078515f2b67c23..7c4d3d9ca830a8b4591ce7c63209b4dcb8e0f128 100644 (file)
@@ -1,6 +1,5 @@
 /* An expandable hash tables datatype.  
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010
-   Free Software Foundation, Inc.
+   Copyright (C) 1999-2017 Free Software Foundation, Inc.
    Contributed by Vladimir Makarov (vmakarov@cygnus.com).
 
 This file is part of the libiberty library.
@@ -194,14 +193,6 @@ higher_prime_index (unsigned long n)
   return low;
 }
 
-/* Returns a hash code for P.  */
-
-static hashval_t
-hash_pointer (const PTR p)
-{
-  return (hashval_t) ((intptr_t)p >> 3);
-}
-
 /* Returns non-zero if P1 and P2 are equal.  */
 
 static int
@@ -970,17 +961,17 @@ iterative_hash (const PTR k_in /* the key */,
   c += length;
   switch(len)              /* all the case statements fall through */
     {
-    case 11: c+=((hashval_t)k[10]<<24);
-    case 10: c+=((hashval_t)k[9]<<16);
-    case 9 : c+=((hashval_t)k[8]<<8);
+    case 11: c+=((hashval_t)k[10]<<24);        /* fall through */
+    case 10: c+=((hashval_t)k[9]<<16); /* fall through */
+    case 9 : c+=((hashval_t)k[8]<<8);  /* fall through */
       /* the first byte of c is reserved for the length */
-    case 8 : b+=((hashval_t)k[7]<<24);
-    case 7 : b+=((hashval_t)k[6]<<16);
-    case 6 : b+=((hashval_t)k[5]<<8);
-    case 5 : b+=k[4];
-    case 4 : a+=((hashval_t)k[3]<<24);
-    case 3 : a+=((hashval_t)k[2]<<16);
-    case 2 : a+=((hashval_t)k[1]<<8);
+    case 8 : b+=((hashval_t)k[7]<<24); /* fall through */
+    case 7 : b+=((hashval_t)k[6]<<16); /* fall through */
+    case 6 : b+=((hashval_t)k[5]<<8);  /* fall through */
+    case 5 : b+=k[4];                  /* fall through */
+    case 4 : a+=((hashval_t)k[3]<<24); /* fall through */
+    case 3 : a+=((hashval_t)k[2]<<16); /* fall through */
+    case 2 : a+=((hashval_t)k[1]<<8);  /* fall through */
     case 1 : a+=k[0];
       /* case 0: nothing left to add */
     }
@@ -988,3 +979,19 @@ iterative_hash (const PTR k_in /* the key */,
   /*-------------------------------------------- report the result */
   return c;
 }
+
+/* Returns a hash code for pointer P. Simplified version of evahash */
+
+static hashval_t
+hash_pointer (const PTR p)
+{
+  intptr_t v = (intptr_t) p;
+  unsigned a, b, c;
+
+  a = b = 0x9e3779b9;
+  a += v >> (sizeof (intptr_t) * CHAR_BIT / 2);
+  b += v & (((intptr_t) 1 << (sizeof (intptr_t) * CHAR_BIT / 2)) - 1);
+  c = 0x42135234;
+  mix (a, b, c);
+  return c;
+}
This page took 0.026194 seconds and 4 git commands to generate.