Bug 415262 - "Make general use of new NSPR rotate macros" [p=swsnyder@insightbb.com (Steve Snyder) r=wtc sr=dbaron a=blocking1.9+]
authorreed@reedloden.com
Wed, 13 Feb 2008 03:34:46 -0800
changeset 11667 d0718b07784066853614d26428aa301aed933b23
parent 11666 0e8661cba008899ab67d92e6048a9d3a51b0bc3c
child 11668 822b8557578ca8035f3bf8d6c69856780abe70dc
push idunknown
push userunknown
push dateunknown
reviewerswtc, dbaron, blocking1.9
bugs415262
milestone1.9b4pre
Bug 415262 - "Make general use of new NSPR rotate macros" [p=swsnyder@insightbb.com (Steve Snyder) r=wtc sr=dbaron a=blocking1.9+]
content/base/src/nsDOMAttributeMap.h
content/xul/document/src/nsElementMap.cpp
netwerk/cache/src/nsDiskCacheDevice.cpp
netwerk/protocol/http/src/nsHttp.cpp
rdf/base/src/nsRDFService.cpp
xpcom/ds/nsCRT.cpp
xpcom/ds/nsStaticNameTable.cpp
xpcom/glue/nsTHashtable.cpp
xpcom/glue/pldhash.c
--- a/content/base/src/nsDOMAttributeMap.h
+++ b/content/base/src/nsDOMAttributeMap.h
@@ -42,16 +42,17 @@
 
 #ifndef nsDOMAttributeMap_h___
 #define nsDOMAttributeMap_h___
 
 #include "nsIDOMNamedNodeMap.h"
 #include "nsString.h"
 #include "nsInterfaceHashtable.h"
 #include "nsCycleCollectionParticipant.h"
+#include "prbit.h"
 
 class nsIAtom;
 class nsIContent;
 class nsDOMAttribute;
 class nsINodeInfo;
 class nsIDocument;
 
 /**
@@ -99,18 +100,17 @@ public:
     }
 
   static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
   static PLDHashNumber HashKey(KeyTypePointer aKey)
     {
       if (!aKey)
         return 0;
 
-      return (aKey->mNamespaceID >> 28) ^
-             (aKey->mNamespaceID << 4) ^
+      return PR_ROTATE_LEFT32(static_cast<PRUint32>aKey->mNamespaceID, 4) ^
              NS_PTR_TO_INT32(aKey->mLocalName);
     }
   enum { ALLOW_MEMMOVE = PR_TRUE };
 
 private:
   nsAttrKey mKey;
 };
 
--- a/content/xul/document/src/nsElementMap.cpp
+++ b/content/xul/document/src/nsElementMap.cpp
@@ -49,16 +49,17 @@
 
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsElementMap.h"
 #include "nsString.h"
 #include "nsIAtom.h"
 #include "nsReadableUtils.h"
 #include "prlog.h"
+#include "prbit.h"
 
 #ifdef PR_LOGGING
 static PRLogModuleInfo* gMapLog;
 #endif
 
 static void* PR_CALLBACK AllocTable(void* aPool, PRSize aSize)
 {
     return new char[aSize];
@@ -410,17 +411,17 @@ nsElementMap::EnumerateImpl(PLHashEntry*
 
 
 PLHashNumber
 nsElementMap::Hash(const void* aKey)
 {
     PLHashNumber result = 0;
     const PRUnichar* s = reinterpret_cast<const PRUnichar*>(aKey);
     while (*s != nsnull) {
-        result = (result >> 28) ^ (result << 4) ^ *s;
+        result = PR_ROTATE_LEFT32(result, 4) ^ *s;
         ++s;
     }
     return result;
 }
 
 
 PRIntn
 nsElementMap::Compare(const void* aLeft, const void* aRight)
--- a/netwerk/cache/src/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/src/nsDiskCacheDevice.cpp
@@ -50,16 +50,17 @@
 #define INCL_DOSERRORS
 #include <os2.h>
 #else
 // XXX add necessary include file for ftruncate (or equivalent)
 #endif
 
 #include "prtypes.h"
 #include "prthread.h"
+#include "prbit.h"
 
 #include "private/pprio.h"
 
 #include "nsDiskCacheDevice.h"
 #include "nsDiskCacheEntry.h"
 #include "nsDiskCacheMap.h"
 #include "nsDiskCacheStreams.h"
 
@@ -244,17 +245,17 @@ NS_IMETHODIMP nsDiskCacheDeviceInfo::Get
  *  map files may become invalid, and therefore the kCurrentVersion needs
  *  to be revised.
  */
 PLDHashNumber
 nsDiskCache::Hash(const char * key)
 {
     PLDHashNumber h = 0;
     for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
-        h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
+        h = PR_ROTATE_LEFT32(h, 4) ^ *s;
     return (h == 0 ? ULONG_MAX : h);
 }
 
 
 nsresult
 nsDiskCache::Truncate(PRFileDesc *  fd, PRUint32  newEOF)
 {
     // use modified SetEOF from nsFileStreams::SetEOF()
--- a/netwerk/protocol/http/src/nsHttp.cpp
+++ b/netwerk/protocol/http/src/nsHttp.cpp
@@ -36,16 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsHttp.h"
 #include "nsAutoLock.h"
 #include "pldhash.h"
 #include "nsCRT.h"
+#include "prbit.h"
 
 #if defined(PR_LOGGING)
 PRLogModuleInfo *gHttpLog = nsnull;
 #endif
 
 // define storage for all atoms
 #define HTTP_ATOM(_name, _value) nsHttpAtom nsHttp::_name = { _value };
 #include "nsHttpAtomList.h"
@@ -90,17 +91,17 @@ NewHeapAtom(const char *value) {
 }
 
 // Hash string ignore case, based on PL_HashString
 PR_STATIC_CALLBACK(PLDHashNumber)
 StringHash(PLDHashTable *table, const void *key)
 {
     PLDHashNumber h = 0;
     for (const char *s = reinterpret_cast<const char*>(key); *s; ++s)
-        h = (h >> 28) ^ (h << 4) ^ nsCRT::ToLower(*s);
+        h = PR_ROTATE_LEFT32(h, 4) ^ nsCRT::ToLower(*s);
     return h;
 }
 
 PR_STATIC_CALLBACK(PRBool)
 StringCompare(PLDHashTable *table, const PLDHashEntryHdr *entry,
               const void *testKey)
 {
     const void *entryKey =
--- a/rdf/base/src/nsRDFService.cpp
+++ b/rdf/base/src/nsRDFService.cpp
@@ -83,16 +83,17 @@
 #include "plhash.h"
 #include "plstr.h"
 #include "prlog.h"
 #include "prprf.h"
 #include "prmem.h"
 #include "rdf.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
+#include "prbit.h"
 
 ////////////////////////////////////////////////////////////////////////
 
 static NS_DEFINE_CID(kRDFXMLDataSourceCID,    NS_RDFXMLDATASOURCE_CID);
 static NS_DEFINE_CID(kRDFDefaultResourceCID,  NS_RDFDEFAULTRESOURCE_CID);
 
 static NS_DEFINE_IID(kIRDFLiteralIID,         NS_IRDFLITERAL_IID);
 static NS_DEFINE_IID(kIRDFDateIID,         NS_IRDFDATE_IID);
@@ -403,17 +404,17 @@ struct BlobHashEntry : public PLDHashEnt
     HashKey(PLDHashTable *table, const void *key)
     {
         const BlobImpl::Data *data =
             static_cast<const BlobImpl::Data *>(key);
 
         const PRUint8 *p = data->mBytes, *limit = p + data->mLength;
         PLDHashNumber h = 0;
         for ( ; p < limit; ++p)
-            h = (h >> 28) ^ (h << 4) ^ *p;
+            h = PR_ROTATE_LEFT32(h, 4) ^ *p;
         return h;
     }
 
     static PRBool PR_CALLBACK
     MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
                const void *key)
     {
         const BlobHashEntry *entry =
--- a/xpcom/ds/nsCRT.cpp
+++ b/xpcom/ds/nsCRT.cpp
@@ -49,19 +49,20 @@
  * In general, if you pass a null into any of these string compare
  * routines, we simply return 0.
  */
 
 
 #include "nsCRT.h"
 #include "nsIServiceManager.h"
 #include "nsCharTraits.h"
+#include "prbit.h"
 
 #define ADD_TO_HASHVAL(hashval, c) \
-    hashval = (hashval>>28) ^ (hashval<<4) ^ (c)
+    hashval = PR_ROTATE_LEFT32(hashval, 4) ^ (c);
 
 //----------------------------------------------------------------------
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // My lovely strtok routine
 
 #define IS_DELIM(m, c)          ((m)[(c) >> 3] & (1 << ((c) & 7)))
@@ -341,18 +342,17 @@ PRUint32 nsCRT::HashCodeAsUTF8(const PRU
 }
 
 PRUint32 nsCRT::BufferHashCode(const PRUnichar* s, PRUint32 len)
 {
   PRUint32 h = 0;
   const PRUnichar* done = s + len;
 
   while ( s < done )
-    h = (h>>28) ^ (h<<4) ^ PRUint16(*s++); // cast to unsigned to prevent possible sign extension
-
+    h = PR_ROTATE_LEFT32(h, 4) ^ PRUint16(*s++); // cast to unsigned to prevent possible sign extension
   return h;
 }
 
 // This should use NSPR but NSPR isn't exporting its PR_strtoll function
 // Until then...
 PRInt64 nsCRT::atoll(const char *str)
 {
     if (!str)
--- a/xpcom/ds/nsStaticNameTable.cpp
+++ b/xpcom/ds/nsStaticNameTable.cpp
@@ -39,16 +39,17 @@
 
 /* Class to manage lookup of static names in a table. */
 
 #include "nsCRT.h"
 
 #include "nscore.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
+#include "prbit.h"
 
 #define PL_ARENA_CONST_ALIGN_MASK 3
 #include "nsStaticNameTable.h"
 
 struct NameTableKey
 {
     NameTableKey(const nsAFlatCString* aKeyStr)
         : mIsUnichar(PR_FALSE)
@@ -107,24 +108,24 @@ PR_STATIC_CALLBACK(PLDHashNumber)
 caseInsensitiveStringHashKey(PLDHashTable *table, const void *key)
 {
     PLDHashNumber h = 0;
     const NameTableKey* tableKey = static_cast<const NameTableKey*>(key);
     if (tableKey->mIsUnichar) {
         for (const PRUnichar* s = tableKey->mKeyStr.m2b->get();
              *s != '\0';
              s++)
-            h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ (*s & ~0x20);
+            h = PR_ROTATE_LEFT32(h, 4) ^ (*s & ~0x20);
     } else {
         for (const unsigned char* s =
                  reinterpret_cast<const unsigned char*>
                                  (tableKey->mKeyStr.m1b->get());
              *s != '\0';
              s++)
-            h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ (*s & ~0x20);
+            h = PR_ROTATE_LEFT32(h, 4) ^ (*s & ~0x20);
     }
     return h;
 }
 
 static const struct PLDHashTableOps nametable_CaseInsensitiveHashTableOps = {
     PL_DHashAllocTable,
     PL_DHashFreeTable,
     caseInsensitiveStringHashKey,
--- a/xpcom/glue/nsTHashtable.cpp
+++ b/xpcom/glue/nsTHashtable.cpp
@@ -32,16 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
+#include "prbit.h"
 
 PRUint32
 HashString( const nsAString& aStr )
 {
   PRUint32 code = 0;
 
 #ifdef MOZILLA_INTERNAL_API
   nsAString::const_iterator begin, end;
@@ -49,17 +50,17 @@ HashString( const nsAString& aStr )
   aStr.EndReading(end);
 #else
   const PRUnichar *begin, *end;
   PRUint32 len = NS_StringGetData(aStr, &begin);
   end = begin + len;
 #endif
 
   while (begin != end) {
-    code = (code>>28) ^ (code<<4) ^ PRUint32(*begin);
+    code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*begin);
     ++begin;
   }
 
   return code;
 }
 
 PRUint32
 HashString( const nsACString& aStr )
@@ -72,43 +73,43 @@ HashString( const nsACString& aStr )
   aStr.EndReading(end);
 #else
   const char *begin, *end;
   PRUint32 len = NS_CStringGetData(aStr, &begin);
   end = begin + len;
 #endif
 
   while (begin != end) {
-    code = (code>>28) ^ (code<<4) ^ PRUint32(*begin);
+    code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*begin);
     ++begin;
   }
 
   return code;
 }
 
 PRUint32
 HashString(const char *str)
 {
   PRUint32 code = 0;
 
   while (*str) {
-    code = (code>>28) ^ (code<<4) ^ PRUint32(*str);
+    code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*str);
     ++str;
   }
 
   return code;
 }
 
 PRUint32
 HashString(const PRUnichar *str)
 {
   PRUint32 code = 0;
 
   while (*str) {
-    code = (code>>28) ^ (code<<4) ^ PRUint32(*str);
+    code = PR_ROTATE_LEFT32(code, 4) ^ PRUint32(*str);
     ++str;
   }
 
   return code;
 }
 
 PLDHashOperator
 PL_DHashStubEnumRemove(PLDHashTable    *table,
@@ -119,16 +120,16 @@ PL_DHashStubEnumRemove(PLDHashTable    *
   return PL_DHASH_REMOVE;
 }
 
 PRUint32 nsIDHashKey::HashKey(const nsID* id)
 {
   PRUint32 h = id->m0;
   PRUint32 i;
 
-  h = (h>>28) ^ (h<<4) ^ id->m1;
-  h = (h>>28) ^ (h<<4) ^ id->m2;
+  h = PR_ROTATE_LEFT32(h, 4) ^ id->m1;
+  h = PR_ROTATE_LEFT32(h, 4) ^ id->m2;
 
   for (i = 0; i < 8; i++)
-    h = (h>>28) ^ (h<<4) ^ id->m3[i];
+    h = PR_ROTATE_LEFT32(h, 4) ^ id->m3[i];
 
   return h;
 }
--- a/xpcom/glue/pldhash.c
+++ b/xpcom/glue/pldhash.c
@@ -99,17 +99,17 @@ PL_DHashFreeTable(PLDHashTable *table, v
 PLDHashNumber
 PL_DHashStringKey(PLDHashTable *table, const void *key)
 {
     PLDHashNumber h;
     const unsigned char *s;
 
     h = 0;
     for (s = key; *s != '\0'; s++)
-        h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
+        h = PR_ROTATE_LEFT32(h, 4) ^ *s;
     return h;
 }
 
 PLDHashNumber
 PL_DHashVoidPtrKeyStub(PLDHashTable *table, const void *key)
 {
     return (PLDHashNumber)(unsigned long)key >> 2;
 }