зеркало из https://github.com/mozilla/gecko-dev.git
Bug 729940 - Part 2: Stop using crappy hash functions in Gecko. r=bz
--HG-- extra : rebase_source : 6fa267a89878cc1a766d8618569debcea9b12e48
This commit is contained in:
Родитель
f584e08122
Коммит
1fc1dc1879
|
@ -60,6 +60,7 @@
|
||||||
#include "nsPrincipal.h"
|
#include "nsPrincipal.h"
|
||||||
|
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -801,7 +802,7 @@ nsPrincipal::GetHashValue(PRUint32* aValue)
|
||||||
|
|
||||||
// If there is a certificate, it takes precendence over the codebase.
|
// If there is a certificate, it takes precendence over the codebase.
|
||||||
if (mCert) {
|
if (mCert) {
|
||||||
*aValue = nsCRT::HashCode(mCert->fingerprint.get());
|
*aValue = HashString(mCert->fingerprint);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*aValue = nsScriptSecurityManager::HashPrincipalByOrigin(this);
|
*aValue = nsScriptSecurityManager::HashPrincipalByOrigin(this);
|
||||||
|
|
|
@ -51,10 +51,9 @@
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
#include "prprf.h"
|
#include "prprf.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
namespace css = mozilla::css;
|
using namespace mozilla;
|
||||||
|
|
||||||
using mozilla::SVGAttrValueWrapper;
|
|
||||||
|
|
||||||
#define MISC_STR_PTR(_cont) \
|
#define MISC_STR_PTR(_cont) \
|
||||||
reinterpret_cast<void*>((_cont)->mStringBits & NS_ATTRVALUE_POINTERVALUE_MASK)
|
reinterpret_cast<void*>((_cont)->mStringBits & NS_ATTRVALUE_POINTERVALUE_MASK)
|
||||||
|
@ -392,7 +391,7 @@ nsAttrValue::SetTo(const nsSVGLength2& aValue, const nsAString* aSerialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGLengthList& aValue,
|
nsAttrValue::SetTo(const SVGLengthList& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as a length list, there's no need to store
|
// While an empty string will parse as a length list, there's no need to store
|
||||||
|
@ -404,7 +403,7 @@ nsAttrValue::SetTo(const mozilla::SVGLengthList& aValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGNumberList& aValue,
|
nsAttrValue::SetTo(const SVGNumberList& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as a number list, there's no need to store
|
// While an empty string will parse as a number list, there's no need to store
|
||||||
|
@ -422,7 +421,7 @@ nsAttrValue::SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGPathData& aValue,
|
nsAttrValue::SetTo(const SVGPathData& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as path data, there's no need to store it
|
// While an empty string will parse as path data, there's no need to store it
|
||||||
|
@ -434,7 +433,7 @@ nsAttrValue::SetTo(const mozilla::SVGPathData& aValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGPointList& aValue,
|
nsAttrValue::SetTo(const SVGPointList& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as a point list, there's no need to store
|
// While an empty string will parse as a point list, there's no need to store
|
||||||
|
@ -446,14 +445,14 @@ nsAttrValue::SetTo(const mozilla::SVGPointList& aValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue,
|
nsAttrValue::SetTo(const SVGAnimatedPreserveAspectRatio& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
SetSVGType(eSVGPreserveAspectRatio, &aValue, aSerialized);
|
SetSVGType(eSVGPreserveAspectRatio, &aValue, aSerialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGStringList& aValue,
|
nsAttrValue::SetTo(const SVGStringList& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as a string list, there's no need to store
|
// While an empty string will parse as a string list, there's no need to store
|
||||||
|
@ -465,7 +464,7 @@ nsAttrValue::SetTo(const mozilla::SVGStringList& aValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SetTo(const mozilla::SVGTransformList& aValue,
|
nsAttrValue::SetTo(const SVGTransformList& aValue,
|
||||||
const nsAString* aSerialized)
|
const nsAString* aSerialized)
|
||||||
{
|
{
|
||||||
// While an empty string will parse as a transform list, there's no need to
|
// While an empty string will parse as a transform list, there's no need to
|
||||||
|
@ -764,7 +763,7 @@ nsAttrValue::HashValue() const
|
||||||
nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
|
nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
|
||||||
if (str) {
|
if (str) {
|
||||||
PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1;
|
PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1;
|
||||||
return nsCRT::HashCode(static_cast<PRUnichar*>(str->Data()), len);
|
return HashString(static_cast<PRUnichar*>(str->Data()), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -812,14 +811,14 @@ nsAttrValue::HashValue() const
|
||||||
}
|
}
|
||||||
case eAtomArray:
|
case eAtomArray:
|
||||||
{
|
{
|
||||||
PRUint32 retval = 0;
|
PRUint32 hash = 0;
|
||||||
PRUint32 count = cont->mAtomArray->Length();
|
PRUint32 count = cont->mAtomArray->Length();
|
||||||
for (nsCOMPtr<nsIAtom> *cur = cont->mAtomArray->Elements(),
|
for (nsCOMPtr<nsIAtom> *cur = cont->mAtomArray->Elements(),
|
||||||
*end = cur + count;
|
*end = cur + count;
|
||||||
cur != end; ++cur) {
|
cur != end; ++cur) {
|
||||||
retval ^= NS_PTR_TO_INT32(cur->get());
|
hash = AddToHash(hash, cur->get());
|
||||||
}
|
}
|
||||||
return retval;
|
return hash;
|
||||||
}
|
}
|
||||||
case eDoubleValue:
|
case eDoubleValue:
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,8 +55,8 @@
|
||||||
#include "nsINameSpaceManager.h"
|
#include "nsINameSpaceManager.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
#include "nsCRT.h"
|
|
||||||
#include "nsHashKeys.h"
|
#include "nsHashKeys.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
// Magic namespace id that means "match all namespaces". This is
|
// Magic namespace id that means "match all namespaces". This is
|
||||||
// negative so it won't collide with actual namespace constants.
|
// negative so it won't collide with actual namespace constants.
|
||||||
|
@ -204,10 +204,8 @@ struct nsContentListKey
|
||||||
|
|
||||||
inline PRUint32 GetHash(void) const
|
inline PRUint32 GetHash(void) const
|
||||||
{
|
{
|
||||||
return
|
PRUint32 hash = mozilla::HashString(mTagname);
|
||||||
HashString(mTagname) ^
|
return mozilla::AddToHash(hash, mRootNode, mMatchNameSpaceId);
|
||||||
(NS_PTR_TO_INT32(mRootNode) << 12) ^
|
|
||||||
(mMatchNameSpaceId << 24);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsINode* const mRootNode; // Weak ref
|
nsINode* const mRootNode; // Weak ref
|
||||||
|
@ -490,8 +488,8 @@ public:
|
||||||
|
|
||||||
PRUint32 GetHash(void) const
|
PRUint32 GetHash(void) const
|
||||||
{
|
{
|
||||||
return NS_PTR_TO_INT32(mRootNode) ^ (NS_PTR_TO_INT32(mFunc) << 12) ^
|
PRUint32 hash = mozilla::HashString(mString);
|
||||||
nsCRT::HashCode(mString.BeginReading(), mString.Length());
|
return mozilla::AddToHash(hash, mRootNode, mFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -112,8 +112,7 @@ public:
|
||||||
if (!aKey)
|
if (!aKey)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return PR_ROTATE_LEFT32(static_cast<PRUint32>(aKey->mNamespaceID), 4) ^
|
return mozilla::HashGeneric(aKey->mNamespaceID, aKey->mLocalName);
|
||||||
NS_PTR_TO_INT32(aKey->mLocalName);
|
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
|
|
@ -238,8 +238,7 @@ public:
|
||||||
static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; }
|
static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return (NS_PTR_TO_INT32(aKey->mCallback) >> 2) ^
|
return mozilla::HashGeneric(aKey->mCallback, aKey->mData);
|
||||||
(NS_PTR_TO_INT32(aKey->mData));
|
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
#include "nsHTMLStyleSheet.h"
|
#include "nsHTMLStyleSheet.h"
|
||||||
#include "nsRuleWalker.h"
|
#include "nsRuleWalker.h"
|
||||||
#include "prmem.h"
|
#include "prmem.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
nsMappedAttributes::nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
nsMappedAttributes::nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
||||||
nsMapRuleToAttributesFunc aMapRuleFunc)
|
nsMapRuleToAttributesFunc aMapRuleFunc)
|
||||||
|
@ -176,14 +179,16 @@ nsMappedAttributes::Equals(const nsMappedAttributes* aOther) const
|
||||||
PRUint32
|
PRUint32
|
||||||
nsMappedAttributes::HashValue() const
|
nsMappedAttributes::HashValue() const
|
||||||
{
|
{
|
||||||
PRUint32 value = NS_PTR_TO_INT32(mRuleMapper);
|
PRUint32 hash = HashGeneric(mRuleMapper);
|
||||||
|
|
||||||
PRUint32 i;
|
PRUint32 i;
|
||||||
for (i = 0; i < mAttrCount; ++i) {
|
for (i = 0; i < mAttrCount; ++i) {
|
||||||
value ^= Attrs()[i].mName.HashValue() ^ Attrs()[i].mValue.HashValue();
|
hash = AddToHash(hash,
|
||||||
|
Attrs()[i].mName.HashValue(),
|
||||||
|
Attrs()[i].mValue.HashValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
|
static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
#define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/"
|
#define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/"
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
#include "nsHashKeys.h"
|
#include "nsHashKeys.h"
|
||||||
#include "nsCCUncollectableMarker.h"
|
#include "nsCCUncollectableMarker.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
#ifdef MOZ_LOGGING
|
#ifdef MOZ_LOGGING
|
||||||
// so we can get logging even in release builds
|
// so we can get logging even in release builds
|
||||||
#define FORCE_PR_LOG 1
|
#define FORCE_PR_LOG 1
|
||||||
|
@ -75,6 +77,9 @@ nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
||||||
reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key);
|
reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key);
|
||||||
|
|
||||||
if (node->mName) {
|
if (node->mName) {
|
||||||
|
// Ideally, we'd return node->mName->hash() here. But that doesn't work at
|
||||||
|
// the moment because node->mName->hash() is not the same as
|
||||||
|
// HashString(*(node->mNameString)). See bug 732815.
|
||||||
return HashString(nsDependentAtomString(node->mName));
|
return HashString(nsDependentAtomString(node->mName));
|
||||||
}
|
}
|
||||||
return HashString(*(node->mNameString));
|
return HashString(*(node->mNameString));
|
||||||
|
|
|
@ -102,7 +102,7 @@ public:
|
||||||
static KeyTypePointer KeyToPointer(KeyType& key) { return &key; }
|
static KeyTypePointer KeyToPointer(KeyType& key) { return &key; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer key)
|
static PLDHashNumber HashKey(KeyTypePointer key)
|
||||||
{
|
{
|
||||||
return (NS_PTR_TO_INT32(key->mImage) ^ NS_PTR_TO_INT32(key->mCanvas)) >> 2;
|
return HashGeneric(key->mImage, key->mCanvas);
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
#include "nsIWeakReferenceUtils.h"
|
#include "nsIWeakReferenceUtils.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
#include "nsUnicharUtils.h"
|
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
#include "nsInterfaceHashtable.h"
|
#include "nsInterfaceHashtable.h"
|
||||||
#include "nsDataHashtable.h"
|
#include "nsDataHashtable.h"
|
||||||
|
@ -57,39 +56,6 @@
|
||||||
class nsFormControlList;
|
class nsFormControlList;
|
||||||
class nsIMutableArray;
|
class nsIMutableArray;
|
||||||
|
|
||||||
/**
|
|
||||||
* hashkey wrapper using nsAString KeyType
|
|
||||||
*
|
|
||||||
* @see nsTHashtable::EntryType for specification
|
|
||||||
*/
|
|
||||||
class nsStringCaseInsensitiveHashKey : public PLDHashEntryHdr
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef const nsAString& KeyType;
|
|
||||||
typedef const nsAString* KeyTypePointer;
|
|
||||||
nsStringCaseInsensitiveHashKey(KeyTypePointer aStr) : mStr(*aStr) { } //take it easy just deal HashKey
|
|
||||||
nsStringCaseInsensitiveHashKey(const nsStringCaseInsensitiveHashKey& toCopy) : mStr(toCopy.mStr) { }
|
|
||||||
~nsStringCaseInsensitiveHashKey() { }
|
|
||||||
|
|
||||||
KeyType GetKey() const { return mStr; }
|
|
||||||
bool KeyEquals(const KeyTypePointer aKey) const
|
|
||||||
{
|
|
||||||
return mStr.Equals(*aKey, nsCaseInsensitiveStringComparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
||||||
static PLDHashNumber HashKey(const KeyTypePointer aKey)
|
|
||||||
{
|
|
||||||
nsAutoString tmKey(*aKey);
|
|
||||||
ToLowerCase(tmKey);
|
|
||||||
return HashString(tmKey);
|
|
||||||
}
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
|
||||||
|
|
||||||
private:
|
|
||||||
const nsString mStr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class nsHTMLFormElement : public nsGenericHTMLElement,
|
class nsHTMLFormElement : public nsGenericHTMLElement,
|
||||||
public nsIDOMHTMLFormElement,
|
public nsIDOMHTMLFormElement,
|
||||||
public nsIWebProgressListener,
|
public nsIWebProgressListener,
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
#include "txKey.h"
|
#include "txKey.h"
|
||||||
#include "txXSLTPatterns.h"
|
#include "txXSLTPatterns.h"
|
||||||
#include "txNamespaceMap.h"
|
#include "txNamespaceMap.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* txKeyFunctionCall
|
* txKeyFunctionCall
|
||||||
|
@ -163,10 +166,13 @@ txKeyValueHashEntry::KeyEquals(KeyTypePointer aKey) const
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
txKeyValueHashEntry::HashKey(KeyTypePointer aKey)
|
txKeyValueHashEntry::HashKey(KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return aKey->mKeyName.mNamespaceID ^
|
const txKeyValueHashKey* key =
|
||||||
NS_PTR_TO_INT32(aKey->mKeyName.mLocalName.get()) ^
|
static_cast<const txKeyValueHashKey*>(aKey);
|
||||||
aKey->mRootIdentifier ^
|
|
||||||
HashString(aKey->mKeyValue);
|
return AddToHash(HashString(key->mKeyValue),
|
||||||
|
key->mKeyName.mNamespaceID,
|
||||||
|
key->mRootIdentifier,
|
||||||
|
key->mKeyName.mLocalName.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -179,9 +185,11 @@ txIndexedKeyHashEntry::KeyEquals(KeyTypePointer aKey) const
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
txIndexedKeyHashEntry::HashKey(KeyTypePointer aKey)
|
txIndexedKeyHashEntry::HashKey(KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return aKey->mKeyName.mNamespaceID ^
|
const txIndexedKeyHashKey* key =
|
||||||
NS_PTR_TO_INT32(aKey->mKeyName.mLocalName.get()) ^
|
static_cast<const txIndexedKeyHashKey*>(aKey);
|
||||||
aKey->mRootIdentifier;
|
return HashGeneric(key->mKeyName.mNamespaceID,
|
||||||
|
key->mRootIdentifier,
|
||||||
|
key->mKeyName.mLocalName.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -109,9 +109,8 @@ public:
|
||||||
return "nsRDFConInstanceTestNode::Element"; }
|
return "nsRDFConInstanceTestNode::Element"; }
|
||||||
|
|
||||||
virtual PLHashNumber Hash() const {
|
virtual PLHashNumber Hash() const {
|
||||||
return (PLHashNumber(NS_PTR_TO_INT32(mContainer.get())) >> 4) ^
|
return mozilla::HashGeneric(mContainerTest, mEmptyTest, mContainer.get());
|
||||||
PLHashNumber(mContainerTest) ^
|
}
|
||||||
(PLHashNumber(mEmptyTest) << 4); }
|
|
||||||
|
|
||||||
virtual bool Equals(const MemoryElement& aElement) const {
|
virtual bool Equals(const MemoryElement& aElement) const {
|
||||||
if (aElement.Type() == Type()) {
|
if (aElement.Type() == Type()) {
|
||||||
|
|
|
@ -124,9 +124,8 @@ public:
|
||||||
return "nsRDFPropertyTestNode::Element"; }
|
return "nsRDFPropertyTestNode::Element"; }
|
||||||
|
|
||||||
virtual PLHashNumber Hash() const {
|
virtual PLHashNumber Hash() const {
|
||||||
return PLHashNumber(NS_PTR_TO_INT32(mSource.get())) ^
|
return mozilla::HashGeneric(mSource.get(), mProperty.get(), mTarget.get());
|
||||||
(PLHashNumber(NS_PTR_TO_INT32(mProperty.get())) >> 4) ^
|
}
|
||||||
(PLHashNumber(NS_PTR_TO_INT32(mTarget.get())) >> 12); }
|
|
||||||
|
|
||||||
virtual bool Equals(const MemoryElement& aElement) const {
|
virtual bool Equals(const MemoryElement& aElement) const {
|
||||||
if (aElement.Type() == Type()) {
|
if (aElement.Type() == Type()) {
|
||||||
|
|
|
@ -60,6 +60,8 @@
|
||||||
#define NS_INTERFACE_PREFIX "nsI"
|
#define NS_INTERFACE_PREFIX "nsI"
|
||||||
#define NS_DOM_INTERFACE_PREFIX "nsIDOM"
|
#define NS_DOM_INTERFACE_PREFIX "nsIDOM"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
// Our extended PLDHashEntryHdr
|
// Our extended PLDHashEntryHdr
|
||||||
class GlobalNameMapEntry : public PLDHashEntryHdr
|
class GlobalNameMapEntry : public PLDHashEntryHdr
|
||||||
{
|
{
|
||||||
|
@ -74,7 +76,6 @@ static PLDHashNumber
|
||||||
GlobalNameHashHashKey(PLDHashTable *table, const void *key)
|
GlobalNameHashHashKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
const nsAString *str = static_cast<const nsAString *>(key);
|
const nsAString *str = static_cast<const nsAString *>(key);
|
||||||
|
|
||||||
return HashString(*str);
|
return HashString(*str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "IDBFactory.h"
|
#include "IDBFactory.h"
|
||||||
#include "IndexedDatabaseManager.h"
|
#include "IndexedDatabaseManager.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
USING_INDEXEDDB_NAMESPACE
|
USING_INDEXEDDB_NAMESPACE
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -56,10 +56,12 @@
|
||||||
#include "prmem.h"
|
#include "prmem.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "nsIPluginInstanceOwner.h"
|
#include "nsIPluginInstanceOwner.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
#define NPRUNTIME_JSCLASS_NAME "NPObject JS wrapper class"
|
#define NPRUNTIME_JSCLASS_NAME "NPObject JS wrapper class"
|
||||||
|
|
||||||
using namespace mozilla::plugins::parent;
|
using namespace mozilla::plugins::parent;
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
#include "mozilla/plugins/PluginScriptableObjectParent.h"
|
#include "mozilla/plugins/PluginScriptableObjectParent.h"
|
||||||
using mozilla::plugins::PluginScriptableObjectParent;
|
using mozilla::plugins::PluginScriptableObjectParent;
|
||||||
|
@ -1022,8 +1024,7 @@ static PLDHashNumber
|
||||||
JSObjWrapperHash(PLDHashTable *table, const void *key)
|
JSObjWrapperHash(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
const nsJSObjWrapperKey *e = static_cast<const nsJSObjWrapperKey *>(key);
|
const nsJSObjWrapperKey *e = static_cast<const nsJSObjWrapperKey *>(key);
|
||||||
|
return HashGeneric(e->mJSObj, e->mNpp);
|
||||||
return (PLDHashNumber)((PRWord)e->mJSObj ^ (PRWord)e->mNpp) >> 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -41,7 +41,9 @@
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
|
|
||||||
#include "nsCommandParams.h"
|
#include "nsCommandParams.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
PLDHashTableOps nsCommandParams::sHashOps =
|
PLDHashTableOps nsCommandParams::sHashOps =
|
||||||
{
|
{
|
||||||
|
@ -356,7 +358,7 @@ nsCommandParams::GetOrMakeEntry(const char * name, PRUint8 entryType, HashEntry*
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
nsCommandParams::HashKey(PLDHashTable *table, const void *key)
|
nsCommandParams::HashKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
return nsCRT::HashCode((const char *)key);
|
return HashString((const char *)key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "nsIAtom.h"
|
#include "nsIAtom.h"
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
#include "gfxPattern.h"
|
#include "gfxPattern.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
typedef struct _cairo_scaled_font cairo_scaled_font_t;
|
typedef struct _cairo_scaled_font cairo_scaled_font_t;
|
||||||
|
|
||||||
|
@ -806,7 +807,7 @@ protected:
|
||||||
bool KeyEquals(const KeyTypePointer aKey) const;
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||||
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
||||||
return NS_PTR_TO_INT32(aKey->mFontEntry) ^ aKey->mStyle->Hash();
|
return mozilla::HashGeneric(aKey->mStyle->Hash(), aKey->mFontEntry);
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "nsXPCOMStrings.h"
|
#include "nsXPCOMStrings.h"
|
||||||
#include "casetable.h"
|
#include "casetable.h"
|
||||||
#include "nsUTF8Utils.h"
|
#include "nsUTF8Utils.h"
|
||||||
|
#include "nsHashKeys.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -540,3 +541,33 @@ CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
|
||||||
return leftChar == rightChar;
|
return leftChar == rightChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
PRUint32
|
||||||
|
HashUTF8AsUTF16(const char* aUTF8, PRUint32 aLength, bool* aErr)
|
||||||
|
{
|
||||||
|
PRUint32 hash = 0;
|
||||||
|
const char* s = aUTF8;
|
||||||
|
const char* end = aUTF8 + aLength;
|
||||||
|
|
||||||
|
*aErr = false;
|
||||||
|
|
||||||
|
while (s < end)
|
||||||
|
{
|
||||||
|
PRUint32 ucs4 = UTF8CharEnumerator::NextChar(&s, end, aErr);
|
||||||
|
if (*aErr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ucs4 < PLANE1_BASE) {
|
||||||
|
hash = AddToHash(hash, ucs4);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hash = AddToHash(hash, H_SURROGATE(ucs4), L_SURROGATE(ucs4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
|
@ -163,4 +163,19 @@ CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
|
||||||
const char** aLeftNext, const char** aRightNext,
|
const char** aLeftNext, const char** aRightNext,
|
||||||
bool* aErr);
|
bool* aErr);
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash a UTF8 string as though it were a UTF16 string.
|
||||||
|
*
|
||||||
|
* The value returned is the same as if we converted the string to UTF16 and
|
||||||
|
* then ran HashString() on the result.
|
||||||
|
*
|
||||||
|
* The given |length| is in bytes.
|
||||||
|
*/
|
||||||
|
PRUint32
|
||||||
|
HashUTF8AsUTF16(const char* aUTF8, PRUint32 aLength, bool* aErr);
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
#endif /* nsUnicharUtils_h__ */
|
#endif /* nsUnicharUtils_h__ */
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "mozilla/dom/ContentChild.h"
|
#include "mozilla/dom/ContentChild.h"
|
||||||
|
|
||||||
#include "mozilla/Util.h"
|
#include "mozilla/Util.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
#include "nsXULAppAPI.h"
|
#include "nsXULAppAPI.h"
|
||||||
|
|
||||||
|
@ -106,9 +107,8 @@ public:
|
||||||
|
|
||||||
static PLDHashNumber HashKey(const ValueObserverHashKey *aKey)
|
static PLDHashNumber HashKey(const ValueObserverHashKey *aKey)
|
||||||
{
|
{
|
||||||
PRUint32 strHash = nsCRT::HashCode(aKey->mPrefName.BeginReading(),
|
PLDHashNumber hash = HashString(aKey->mPrefName);
|
||||||
aKey->mPrefName.Length());
|
return AddToHash(hash, aKey->mCallback);
|
||||||
return PR_ROTATE_LEFT32(strHash, 4) ^ NS_PTR_TO_UINT32(aKey->mCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueObserverHashKey(const char *aPref, PrefChangedFunc aCallback) :
|
ValueObserverHashKey(const char *aPref, PrefChangedFunc aCallback) :
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "prbit.h"
|
#include "prbit.h"
|
||||||
#include "nsTraceRefcnt.h"
|
#include "nsTraceRefcnt.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
class nsPrefBranch;
|
class nsPrefBranch;
|
||||||
|
|
||||||
|
@ -71,11 +72,8 @@ class PrefCallback : public PLDHashEntryHdr {
|
||||||
|
|
||||||
static PLDHashNumber HashKey(const PrefCallback *aKey)
|
static PLDHashNumber HashKey(const PrefCallback *aKey)
|
||||||
{
|
{
|
||||||
PRUint32 strHash = nsCRT::HashCode(aKey->mDomain.BeginReading(),
|
PRUint32 hash = mozilla::HashString(aKey->mDomain);
|
||||||
aKey->mDomain.Length());
|
return mozilla::AddToHash(hash, aKey->mCanonical);
|
||||||
|
|
||||||
return PR_ROTATE_LEFT32(strHash, 4) ^
|
|
||||||
NS_PTR_TO_UINT32(aKey->mCanonical);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,9 @@
|
||||||
#include "nsMemory.h"
|
#include "nsMemory.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "prio.h" // for read/write flags, permissions, etc.
|
#include "prio.h" // for read/write flags, permissions, etc.
|
||||||
|
#include "nsHashKeys.h"
|
||||||
|
|
||||||
#include "nsCRT.h"
|
#include "plstr.h"
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
#include "nsIStandardURL.h"
|
#include "nsIStandardURL.h"
|
||||||
#include "nsIURLParser.h"
|
#include "nsIURLParser.h"
|
||||||
|
@ -106,11 +107,10 @@
|
||||||
#include "nsIChannelPolicy.h"
|
#include "nsIChannelPolicy.h"
|
||||||
#include "nsISocketProviderService.h"
|
#include "nsISocketProviderService.h"
|
||||||
#include "nsISocketProvider.h"
|
#include "nsISocketProvider.h"
|
||||||
|
#include "nsIRedirectChannelRegistrar.h"
|
||||||
#include "nsIMIMEHeaderParam.h"
|
#include "nsIMIMEHeaderParam.h"
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
|
|
||||||
#include "nsIRedirectChannelRegistrar.h"
|
|
||||||
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
|
|
||||||
inline already_AddRefed<nsIIOService>
|
inline already_AddRefed<nsIIOService>
|
||||||
|
@ -1618,7 +1618,7 @@ NS_SecurityHashURI(nsIURI* aURI)
|
||||||
nsCAutoString scheme;
|
nsCAutoString scheme;
|
||||||
PRUint32 schemeHash = 0;
|
PRUint32 schemeHash = 0;
|
||||||
if (NS_SUCCEEDED(baseURI->GetScheme(scheme)))
|
if (NS_SUCCEEDED(baseURI->GetScheme(scheme)))
|
||||||
schemeHash = nsCRT::HashCode(scheme.get());
|
schemeHash = mozilla::HashString(scheme);
|
||||||
|
|
||||||
// TODO figure out how to hash file:// URIs
|
// TODO figure out how to hash file:// URIs
|
||||||
if (scheme.EqualsLiteral("file"))
|
if (scheme.EqualsLiteral("file"))
|
||||||
|
@ -1631,17 +1631,16 @@ NS_SecurityHashURI(nsIURI* aURI)
|
||||||
nsCAutoString spec;
|
nsCAutoString spec;
|
||||||
PRUint32 specHash = baseURI->GetSpec(spec);
|
PRUint32 specHash = baseURI->GetSpec(spec);
|
||||||
if (NS_SUCCEEDED(specHash))
|
if (NS_SUCCEEDED(specHash))
|
||||||
specHash = nsCRT::HashCode(spec.get());
|
specHash = mozilla::HashString(spec);
|
||||||
return specHash;
|
return specHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCAutoString host;
|
nsCAutoString host;
|
||||||
PRUint32 hostHash = 0;
|
PRUint32 hostHash = 0;
|
||||||
if (NS_SUCCEEDED(baseURI->GetAsciiHost(host)))
|
if (NS_SUCCEEDED(baseURI->GetAsciiHost(host)))
|
||||||
hostHash = nsCRT::HashCode(host.get());
|
hostHash = mozilla::HashString(host);
|
||||||
|
|
||||||
// XOR to combine hash values
|
return mozilla::AddToHash(schemeHash, hostHash, NS_GetRealPort(baseURI));
|
||||||
return schemeHash ^ hostHash ^ NS_GetRealPort(baseURI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
|
|
||||||
#include "pldhash.h"
|
#include "pldhash.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsCRT.h"
|
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
|
#include "nsHashKeys.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hashtable key class to use with nsTHashtable/nsBaseHashtable
|
* Hashtable key class to use with nsTHashtable/nsBaseHashtable
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
static PLDHashNumber HashKey(const nsIURI* aKey) {
|
static PLDHashNumber HashKey(const nsIURI* aKey) {
|
||||||
nsCAutoString spec;
|
nsCAutoString spec;
|
||||||
const_cast<nsIURI*>(aKey)->GetSpec(spec);
|
const_cast<nsIURI*>(aKey)->GetSpec(spec);
|
||||||
return nsCRT::HashCode(spec.get());
|
return mozilla::HashString(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
|
@ -50,8 +50,9 @@
|
||||||
#include "nsCache.h"
|
#include "nsCache.h"
|
||||||
#include "nsCacheService.h"
|
#include "nsCacheService.h"
|
||||||
#include "nsCacheDevice.h"
|
#include "nsCacheDevice.h"
|
||||||
#include "nsCRT.h"
|
#include "nsHashKeys.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
nsCacheEntry::nsCacheEntry(nsCString * key,
|
nsCacheEntry::nsCacheEntry(nsCString * key,
|
||||||
bool streamBased,
|
bool streamBased,
|
||||||
|
@ -523,7 +524,7 @@ nsCacheEntryHashTable::VisitEntries( PLDHashEnumerator etor, void *arg)
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
return PL_DHashStringKey(table,((nsCString *)key)->get());
|
return HashString(*static_cast<const nsCString *>(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -127,7 +127,7 @@ class nsCookieEntry : public PLDHashEntryHdr
|
||||||
|
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return HashString(*aKey);
|
return mozilla::HashString(*aKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
#include "nsURLHelper.h"
|
#include "nsURLHelper.h"
|
||||||
|
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
#include "mozilla/FunctionTimer.h"
|
#include "mozilla/FunctionTimer.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
#include "mozilla/Telemetry.h"
|
#include "mozilla/Telemetry.h"
|
||||||
|
@ -278,7 +279,7 @@ static PLDHashNumber
|
||||||
HostDB_HashKey(PLDHashTable *table, const void *key)
|
HostDB_HashKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
const nsHostKey *hk = static_cast<const nsHostKey *>(key);
|
const nsHostKey *hk = static_cast<const nsHostKey *>(key);
|
||||||
return PL_DHashStringKey(table, hk->host) ^ RES_KEY_FLAGS(hk->flags) ^ hk->af;
|
return AddToHash(HashString(hk->host), RES_KEY_FLAGS(hk->flags), hk->af);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -40,9 +40,12 @@
|
||||||
#include "nsHttp.h"
|
#include "nsHttp.h"
|
||||||
#include "pldhash.h"
|
#include "pldhash.h"
|
||||||
#include "mozilla/Mutex.h"
|
#include "mozilla/Mutex.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "prbit.h"
|
#include "prbit.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
#if defined(PR_LOGGING)
|
#if defined(PR_LOGGING)
|
||||||
PRLogModuleInfo *gHttpLog = nsnull;
|
PRLogModuleInfo *gHttpLog = nsnull;
|
||||||
#endif
|
#endif
|
||||||
|
@ -98,7 +101,7 @@ StringHash(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
PLDHashNumber h = 0;
|
PLDHashNumber h = 0;
|
||||||
for (const char *s = reinterpret_cast<const char*>(key); *s; ++s)
|
for (const char *s = reinterpret_cast<const char*>(key); *s; ++s)
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ nsCRT::ToLower(*s);
|
h = AddToHash(h, nsCRT::ToLower(*s));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsStaticAtom.h"
|
#include "nsStaticAtom.h"
|
||||||
#include "nsUnicharUtils.h"
|
#include "nsUnicharUtils.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -325,9 +326,7 @@ PLHashTable* nsHTMLTags::gTagAtomTable;
|
||||||
static PLHashNumber
|
static PLHashNumber
|
||||||
HTMLTagsHashCodeUCPtr(const void *key)
|
HTMLTagsHashCodeUCPtr(const void *key)
|
||||||
{
|
{
|
||||||
const PRUnichar *str = (const PRUnichar *)key;
|
return HashString(static_cast<const PRUnichar*>(key));
|
||||||
|
|
||||||
return nsCRT::HashCode(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PRIntn
|
static PRIntn
|
||||||
|
|
|
@ -89,6 +89,9 @@
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsCRTGlue.h"
|
#include "nsCRTGlue.h"
|
||||||
#include "prbit.h"
|
#include "prbit.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -155,7 +158,7 @@ struct ResourceHashEntry : public PLDHashEntryHdr {
|
||||||
static PLDHashNumber
|
static PLDHashNumber
|
||||||
HashKey(PLDHashTable *table, const void *key)
|
HashKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
return nsCRT::HashCode(static_cast<const char *>(key));
|
return HashString(static_cast<const char *>(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -193,7 +196,7 @@ struct LiteralHashEntry : public PLDHashEntryHdr {
|
||||||
static PLDHashNumber
|
static PLDHashNumber
|
||||||
HashKey(PLDHashTable *table, const void *key)
|
HashKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
return nsCRT::HashCode(static_cast<const PRUnichar *>(key));
|
return HashString(static_cast<const PRUnichar *>(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -389,12 +392,7 @@ struct BlobHashEntry : public PLDHashEntryHdr {
|
||||||
{
|
{
|
||||||
const BlobImpl::Data *data =
|
const BlobImpl::Data *data =
|
||||||
static_cast<const BlobImpl::Data *>(key);
|
static_cast<const BlobImpl::Data *>(key);
|
||||||
|
return HashBytes(data->mBytes, data->mLength);
|
||||||
const PRUint8 *p = data->mBytes, *limit = p + data->mLength;
|
|
||||||
PLDHashNumber h = 0;
|
|
||||||
for ( ; p < limit; ++p)
|
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ *p;
|
|
||||||
return h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "PSMRunnable.h"
|
#include "PSMRunnable.h"
|
||||||
#include "nsIConsoleService.h"
|
#include "nsIConsoleService.h"
|
||||||
#include "nsIHttpChannelInternal.h"
|
#include "nsIHttpChannelInternal.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
|
||||||
#include "ssl.h"
|
#include "ssl.h"
|
||||||
#include "ocsp.h"
|
#include "ocsp.h"
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "nsIImageToPixbuf.h"
|
#include "nsIImageToPixbuf.h"
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
#include "nsIObserverService.h"
|
#include "nsIObserverService.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
|
|
||||||
|
#include "nsCRT.h"
|
||||||
#include "nsConsoleMessage.h"
|
#include "nsConsoleMessage.h"
|
||||||
#include "nsTextFormatter.h"
|
#include "nsTextFormatter.h"
|
||||||
#include "nsVersionComparator.h"
|
#include "nsVersionComparator.h"
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
#include "nsAtomTable.h"
|
#include "nsAtomTable.h"
|
||||||
#include "nsStaticAtom.h"
|
#include "nsStaticAtom.h"
|
||||||
|
@ -50,10 +51,13 @@
|
||||||
#include "nsDataHashtable.h"
|
#include "nsDataHashtable.h"
|
||||||
#include "nsHashKeys.h"
|
#include "nsHashKeys.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "nsAutoPtr.h"
|
||||||
|
#include "nsUnicharUtils.h"
|
||||||
|
|
||||||
#define PL_ARENA_CONST_ALIGN_MASK 3
|
#define PL_ARENA_CONST_ALIGN_MASK 3
|
||||||
#include "plarena.h"
|
#include "plarena.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shared hash table for atom lookups.
|
* The shared hash table for atom lookups.
|
||||||
*
|
*
|
||||||
|
@ -192,7 +196,7 @@ AtomTableGetHash(PLDHashTable *table, const void *key)
|
||||||
|
|
||||||
if (k->mUTF8String) {
|
if (k->mUTF8String) {
|
||||||
bool err;
|
bool err;
|
||||||
PRUint32 hash = nsCRT::HashCodeAsUTF16(k->mUTF8String, k->mLength, &err);
|
PRUint32 hash = HashUTF8AsUTF16(k->mUTF8String, k->mLength, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
AtomTableKey* mutableKey = const_cast<AtomTableKey*>(k);
|
AtomTableKey* mutableKey = const_cast<AtomTableKey*>(k);
|
||||||
mutableKey->mUTF8String = nsnull;
|
mutableKey->mUTF8String = nsnull;
|
||||||
|
@ -202,7 +206,7 @@ AtomTableGetHash(PLDHashTable *table, const void *key)
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nsCRT::HashCode(k->mUTF16String, k->mLength);
|
return HashString(k->mUTF16String, k->mLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -55,9 +55,6 @@
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsCharTraits.h"
|
#include "nsCharTraits.h"
|
||||||
#include "nsUTF8Utils.h"
|
#include "nsUTF8Utils.h"
|
||||||
#include "mozilla/HashFunctions.h"
|
|
||||||
|
|
||||||
using namespace mozilla;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -202,108 +199,6 @@ PRUnichar* nsCRT::strndup(const PRUnichar* str, PRUint32 len)
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* |nsCRT::HashCode| is identical to |PL_HashString|, which tests
|
|
||||||
* (http://bugzilla.mozilla.org/showattachment.cgi?attach_id=26596)
|
|
||||||
* show to be the best hash among several other choices.
|
|
||||||
*
|
|
||||||
* We re-implement it here rather than calling it for two reasons:
|
|
||||||
* (1) in this interface, we also calculate the length of the
|
|
||||||
* string being hashed; and (2) the narrow and wide and `buffer' versions here
|
|
||||||
* will hash equivalent strings to the same value, e.g., "Hello" and L"Hello".
|
|
||||||
*/
|
|
||||||
PRUint32 nsCRT::HashCode(const char* str, PRUint32* resultingStrLen)
|
|
||||||
{
|
|
||||||
PRUint32 h = 0;
|
|
||||||
const char* s = str;
|
|
||||||
|
|
||||||
if (!str) return h;
|
|
||||||
|
|
||||||
unsigned char c;
|
|
||||||
while ( (c = *s++) ) {
|
|
||||||
h = AddToHash(h, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( resultingStrLen )
|
|
||||||
*resultingStrLen = (s-str)-1;
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32 nsCRT::HashCode(const char* start, PRUint32 length)
|
|
||||||
{
|
|
||||||
PRUint32 h = 0;
|
|
||||||
const char* s = start;
|
|
||||||
const char* end = start + length;
|
|
||||||
|
|
||||||
unsigned char c;
|
|
||||||
while ( s < end ) {
|
|
||||||
c = *s++;
|
|
||||||
h = AddToHash(h, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32 nsCRT::HashCode(const PRUnichar* str, PRUint32* resultingStrLen)
|
|
||||||
{
|
|
||||||
PRUint32 h = 0;
|
|
||||||
const PRUnichar* s = str;
|
|
||||||
|
|
||||||
if (!str) return h;
|
|
||||||
|
|
||||||
PRUnichar c;
|
|
||||||
while ( (c = *s++) )
|
|
||||||
h = AddToHash(h, c);
|
|
||||||
|
|
||||||
if ( resultingStrLen )
|
|
||||||
*resultingStrLen = (s-str)-1;
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32 nsCRT::HashCode(const PRUnichar* start, PRUint32 length)
|
|
||||||
{
|
|
||||||
PRUint32 h = 0;
|
|
||||||
const PRUnichar* s = start;
|
|
||||||
const PRUnichar* end = start + length;
|
|
||||||
|
|
||||||
PRUnichar c;
|
|
||||||
while ( s < end ) {
|
|
||||||
c = *s++;
|
|
||||||
h = AddToHash(h, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32 nsCRT::HashCodeAsUTF16(const char* start, PRUint32 length,
|
|
||||||
bool* err)
|
|
||||||
{
|
|
||||||
PRUint32 h = 0;
|
|
||||||
const char* s = start;
|
|
||||||
const char* end = start + length;
|
|
||||||
|
|
||||||
*err = false;
|
|
||||||
|
|
||||||
while ( s < end )
|
|
||||||
{
|
|
||||||
PRUint32 ucs4 = UTF8CharEnumerator::NextChar(&s, end, err);
|
|
||||||
if (*err) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ucs4 < PLANE1_BASE) {
|
|
||||||
h = AddToHash(h, ucs4);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
h = AddToHash(h, H_SURROGATE(ucs4), L_SURROGATE(ucs4));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should use NSPR but NSPR isn't exporting its PR_strtoll function
|
// This should use NSPR but NSPR isn't exporting its PR_strtoll function
|
||||||
// Until then...
|
// Until then...
|
||||||
PRInt64 nsCRT::atoll(const char *str)
|
PRInt64 nsCRT::atoll(const char *str)
|
||||||
|
|
|
@ -229,28 +229,6 @@ public:
|
||||||
shared_allocator.deallocate(str, 0 /*we never new or kept the size*/);
|
shared_allocator.deallocate(str, 0 /*we never new or kept the size*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computes the hashcode for a c-string, returns the string length as
|
|
||||||
// an added bonus.
|
|
||||||
static PRUint32 HashCode(const char* str,
|
|
||||||
PRUint32* resultingStrLen = nsnull);
|
|
||||||
|
|
||||||
// Computes the hashcode for a length number of bytes of c-string data.
|
|
||||||
static PRUint32 HashCode(const char* start, PRUint32 length);
|
|
||||||
|
|
||||||
// Computes the hashcode for a ucs2 string, returns the string length
|
|
||||||
// as an added bonus.
|
|
||||||
static PRUint32 HashCode(const PRUnichar* str,
|
|
||||||
PRUint32* resultingStrLen = nsnull);
|
|
||||||
|
|
||||||
// Computes the hashcode for a buffer with a specified length.
|
|
||||||
static PRUint32 HashCode(const PRUnichar* str, PRUint32 strLen);
|
|
||||||
|
|
||||||
// Computes a hashcode for a length number of UTF8
|
|
||||||
// characters. Returns the same hash code as the HashCode method
|
|
||||||
// taking a |PRUnichar*| would if the string were converted to UTF16.
|
|
||||||
static PRUint32 HashCodeAsUTF16(const char* start, PRUint32 length,
|
|
||||||
bool* err);
|
|
||||||
|
|
||||||
// String to longlong
|
// String to longlong
|
||||||
static PRInt64 atoll(const char *str);
|
static PRInt64 atoll(const char *str);
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@
|
||||||
#include "nsIObjectInputStream.h"
|
#include "nsIObjectInputStream.h"
|
||||||
#include "nsIObjectOutputStream.h"
|
#include "nsIObjectOutputStream.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
struct HTEntry : PLDHashEntryHdr
|
struct HTEntry : PLDHashEntryHdr
|
||||||
{
|
{
|
||||||
|
@ -534,7 +537,7 @@ nsCStringKey::~nsCStringKey(void)
|
||||||
PRUint32
|
PRUint32
|
||||||
nsCStringKey::HashCode(void) const
|
nsCStringKey::HashCode(void) const
|
||||||
{
|
{
|
||||||
return nsCRT::HashCode(mStr, (PRUint32*)&mStrLen);
|
return HashString(mStr, mStrLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -661,7 +664,7 @@ nsStringKey::~nsStringKey(void)
|
||||||
PRUint32
|
PRUint32
|
||||||
nsStringKey::HashCode(void) const
|
nsStringKey::HashCode(void) const
|
||||||
{
|
{
|
||||||
return nsCRT::HashCode(mStr, (PRUint32*)&mStrLen);
|
return HashString(mStr, mStrLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -45,10 +45,13 @@
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
#include "prbit.h"
|
#include "prbit.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
#define PL_ARENA_CONST_ALIGN_MASK 3
|
#define PL_ARENA_CONST_ALIGN_MASK 3
|
||||||
#include "nsStaticNameTable.h"
|
#include "nsStaticNameTable.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
struct NameTableKey
|
struct NameTableKey
|
||||||
{
|
{
|
||||||
NameTableKey(const nsAFlatCString* aKeyStr)
|
NameTableKey(const nsAFlatCString* aKeyStr)
|
||||||
|
@ -113,14 +116,14 @@ caseInsensitiveStringHashKey(PLDHashTable *table, const void *key)
|
||||||
for (const PRUnichar* s = tableKey->mKeyStr.m2b->get();
|
for (const PRUnichar* s = tableKey->mKeyStr.m2b->get();
|
||||||
*s != '\0';
|
*s != '\0';
|
||||||
s++)
|
s++)
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ (*s & ~0x20);
|
h = AddToHash(h, *s & ~0x20);
|
||||||
} else {
|
} else {
|
||||||
for (const unsigned char* s =
|
for (const unsigned char* s =
|
||||||
reinterpret_cast<const unsigned char*>
|
reinterpret_cast<const unsigned char*>
|
||||||
(tableKey->mKeyStr.m1b->get());
|
(tableKey->mKeyStr.m1b->get());
|
||||||
*s != '\0';
|
*s != '\0';
|
||||||
s++)
|
s++)
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ (*s & ~0x20);
|
h = AddToHash(h, *s & ~0x20);
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,31 @@
|
||||||
|
|
||||||
#include "nsStringGlue.h"
|
#include "nsStringGlue.h"
|
||||||
#include "nsCRTGlue.h"
|
#include "nsCRTGlue.h"
|
||||||
|
#include "nsUnicharUtils.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
// These are defined analogously to the HashString overloads in mfbt.
|
||||||
|
|
||||||
|
inline PRUint32
|
||||||
|
HashString(const nsAString& aStr)
|
||||||
|
{
|
||||||
|
return HashString(aStr.BeginReading(), aStr.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PRUint32
|
||||||
|
HashString(const nsACString& aStr)
|
||||||
|
{
|
||||||
|
return HashString(aStr.BeginReading(), aStr.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
/** @file nsHashKeys.h
|
/** @file nsHashKeys.h
|
||||||
* standard HashKey classes for nsBaseHashtable and relatives. Each of these
|
* standard HashKey classes for nsBaseHashtable and relatives. Each of these
|
||||||
* classes follows the nsTHashtable::EntryType specification
|
* classes follows the nsTHashtable::EntryType specification
|
||||||
|
@ -72,11 +93,6 @@
|
||||||
* nsHashableHashKey
|
* nsHashableHashKey
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NS_COM_GLUE PRUint32 HashString(const nsAString& aStr);
|
|
||||||
NS_COM_GLUE PRUint32 HashString(const nsACString& aStr);
|
|
||||||
NS_COM_GLUE PRUint32 HashString(const char* aKey);
|
|
||||||
NS_COM_GLUE PRUint32 HashString(const PRUnichar* aKey);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hashkey wrapper using nsAString KeyType
|
* hashkey wrapper using nsAString KeyType
|
||||||
*
|
*
|
||||||
|
@ -101,7 +117,7 @@ public:
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||||
static PLDHashNumber HashKey(const KeyTypePointer aKey)
|
static PLDHashNumber HashKey(const KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return HashString(*aKey);
|
return mozilla::HashString(*aKey);
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
@ -109,6 +125,47 @@ private:
|
||||||
const nsString mStr;
|
const nsString mStr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef MOZILLA_INTERNAL_API
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hashkey wrapper using nsAString KeyType
|
||||||
|
*
|
||||||
|
* This is internal-API only because nsCaseInsensitiveStringComparator is
|
||||||
|
* internal-only.
|
||||||
|
*
|
||||||
|
* @see nsTHashtable::EntryType for specification
|
||||||
|
*/
|
||||||
|
class nsStringCaseInsensitiveHashKey : public PLDHashEntryHdr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef const nsAString& KeyType;
|
||||||
|
typedef const nsAString* KeyTypePointer;
|
||||||
|
|
||||||
|
nsStringCaseInsensitiveHashKey(KeyTypePointer aStr) : mStr(*aStr) { } //take it easy just deal HashKey
|
||||||
|
nsStringCaseInsensitiveHashKey(const nsStringCaseInsensitiveHashKey& toCopy) : mStr(toCopy.mStr) { }
|
||||||
|
~nsStringCaseInsensitiveHashKey() { }
|
||||||
|
|
||||||
|
KeyType GetKey() const { return mStr; }
|
||||||
|
bool KeyEquals(const KeyTypePointer aKey) const
|
||||||
|
{
|
||||||
|
return mStr.Equals(*aKey, nsCaseInsensitiveStringComparator());
|
||||||
|
}
|
||||||
|
|
||||||
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||||
|
static PLDHashNumber HashKey(const KeyTypePointer aKey)
|
||||||
|
{
|
||||||
|
nsAutoString tmKey(*aKey);
|
||||||
|
ToLowerCase(tmKey);
|
||||||
|
return mozilla::HashString(tmKey);
|
||||||
|
}
|
||||||
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
private:
|
||||||
|
const nsString mStr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hashkey wrapper using nsACString KeyType
|
* hashkey wrapper using nsACString KeyType
|
||||||
*
|
*
|
||||||
|
@ -131,7 +188,7 @@ public:
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||||
{
|
{
|
||||||
return HashString(*aKey);
|
return mozilla::HashString(*aKey);
|
||||||
}
|
}
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
@ -328,7 +385,12 @@ public:
|
||||||
bool KeyEquals(KeyTypePointer aKey) const { return aKey->Equals(mID); }
|
bool KeyEquals(KeyTypePointer aKey) const { return aKey->Equals(mID); }
|
||||||
|
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey);
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||||
|
{
|
||||||
|
// Hash the nsID object's raw bytes.
|
||||||
|
return mozilla::HashBytes(aKey, sizeof(KeyType));
|
||||||
|
}
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -362,7 +424,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* KeyToPointer(const char* aKey) { return aKey; }
|
static const char* KeyToPointer(const char* aKey) { return aKey; }
|
||||||
static PLDHashNumber HashKey(const char* aKey) { return HashString(aKey); }
|
static PLDHashNumber HashKey(const char* aKey) { return mozilla::HashString(aKey); }
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -391,7 +453,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey) { return HashString(aKey); }
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return mozilla::HashString(aKey); }
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
@ -421,7 +483,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
||||||
static PLDHashNumber HashKey(KeyTypePointer aKey) { return HashString(aKey); }
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return mozilla::HashString(aKey); }
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
|
|
|
@ -36,83 +36,6 @@
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#include "nsTHashtable.h"
|
#include "nsTHashtable.h"
|
||||||
#include "nsHashKeys.h"
|
|
||||||
#include "prbit.h"
|
|
||||||
#include "mozilla/HashFunctions.h"
|
|
||||||
|
|
||||||
using namespace mozilla;
|
|
||||||
|
|
||||||
PRUint32
|
|
||||||
HashString( const nsAString& aStr )
|
|
||||||
{
|
|
||||||
PRUint32 code = 0;
|
|
||||||
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
|
||||||
nsAString::const_iterator begin, end;
|
|
||||||
aStr.BeginReading(begin);
|
|
||||||
aStr.EndReading(end);
|
|
||||||
#else
|
|
||||||
const PRUnichar *begin, *end;
|
|
||||||
PRUint32 len = NS_StringGetData(aStr, &begin);
|
|
||||||
end = begin + len;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (begin != end) {
|
|
||||||
code = AddToHash(code, *begin);
|
|
||||||
++begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32
|
|
||||||
HashString( const nsACString& aStr )
|
|
||||||
{
|
|
||||||
PRUint32 code = 0;
|
|
||||||
|
|
||||||
#ifdef MOZILLA_INTERNAL_API
|
|
||||||
nsACString::const_iterator begin, end;
|
|
||||||
aStr.BeginReading(begin);
|
|
||||||
aStr.EndReading(end);
|
|
||||||
#else
|
|
||||||
const char *begin, *end;
|
|
||||||
PRUint32 len = NS_CStringGetData(aStr, &begin);
|
|
||||||
end = begin + len;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (begin != end) {
|
|
||||||
code = AddToHash(code, *begin);
|
|
||||||
++begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32
|
|
||||||
HashString(const char *str)
|
|
||||||
{
|
|
||||||
PRUint32 code = 0;
|
|
||||||
|
|
||||||
while (*str) {
|
|
||||||
code = AddToHash(code, *str);
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRUint32
|
|
||||||
HashString(const PRUnichar *str)
|
|
||||||
{
|
|
||||||
PRUint32 code = 0;
|
|
||||||
|
|
||||||
while (*str) {
|
|
||||||
code = AddToHash(code, *str);
|
|
||||||
++str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
PLDHashOperator
|
PLDHashOperator
|
||||||
PL_DHashStubEnumRemove(PLDHashTable *table,
|
PL_DHashStubEnumRemove(PLDHashTable *table,
|
||||||
|
@ -122,17 +45,3 @@ PL_DHashStubEnumRemove(PLDHashTable *table,
|
||||||
{
|
{
|
||||||
return PL_DHASH_REMOVE;
|
return PL_DHASH_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRUint32 nsIDHashKey::HashKey(const nsID* id)
|
|
||||||
{
|
|
||||||
PRUint32 h = id->m0;
|
|
||||||
PRUint32 i;
|
|
||||||
|
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ id->m1;
|
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ id->m2;
|
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
h = PR_ROTATE_LEFT32(h, 4) ^ id->m3[i];
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
|
@ -126,13 +126,7 @@ PL_DHashFreeTable(PLDHashTable *table, void *ptr)
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
PL_DHashStringKey(PLDHashTable *table, const void *key)
|
PL_DHashStringKey(PLDHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
PLDHashNumber h;
|
return HashString(static_cast<const char*>(key));
|
||||||
const unsigned char *s;
|
|
||||||
|
|
||||||
h = 0;
|
|
||||||
for (s = (const unsigned char *) key; *s != '\0'; s++)
|
|
||||||
h = AddToHash(h, *s);
|
|
||||||
return h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PLDHashNumber
|
PLDHashNumber
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
#include "nsIMutableArray.h"
|
#include "nsIMutableArray.h"
|
||||||
#include "nsTraceRefcntImpl.h"
|
#include "nsTraceRefcntImpl.h"
|
||||||
|
|
||||||
|
using namespace mozilla;
|
||||||
|
|
||||||
#define CHECK_mWorkingPath() \
|
#define CHECK_mWorkingPath() \
|
||||||
PR_BEGIN_MACRO \
|
PR_BEGIN_MACRO \
|
||||||
if (mWorkingPath.IsEmpty()) \
|
if (mWorkingPath.IsEmpty()) \
|
||||||
|
@ -2575,7 +2577,7 @@ nsLocalFile::Equals(nsIHashable* aOther, bool *aResult)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
||||||
{
|
{
|
||||||
*aResult = nsCRT::HashCode(mWorkingPath.get());
|
*aResult = HashString(mWorkingPath);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@ static nsresult MacErrorMapper(OSErr inErr);
|
||||||
|
|
||||||
#include "nsNativeCharsetUtils.h"
|
#include "nsNativeCharsetUtils.h"
|
||||||
#include "nsTraceRefcntImpl.h"
|
#include "nsTraceRefcntImpl.h"
|
||||||
|
#include "nsHashKeys.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -2030,7 +2031,7 @@ nsLocalFile::Equals(nsIHashable* aOther, bool *aResult)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
nsLocalFile::GetHashCode(PRUint32 *aResult)
|
||||||
{
|
{
|
||||||
*aResult = nsCRT::HashCode(mPath.get());
|
*aResult = HashString(mPath);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public:
|
||||||
|
|
||||||
bool KeyEquals(const char* aEntity) const { return !strcmp(mNode->mStr, aEntity); }
|
bool KeyEquals(const char* aEntity) const { return !strcmp(mNode->mStr, aEntity); }
|
||||||
static const char* KeyToPointer(const char* aEntity) { return aEntity; }
|
static const char* KeyToPointer(const char* aEntity) { return aEntity; }
|
||||||
static PLDHashNumber HashKey(const char* aEntity) { return HashString(aEntity); }
|
static PLDHashNumber HashKey(const char* aEntity) { return mozilla::HashString(aEntity); }
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
const EntityNode* mNode;
|
const EntityNode* mNode;
|
||||||
|
|
|
@ -41,9 +41,9 @@
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsStringBuffer.h"
|
#include "nsStringBuffer.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
#include "nsCRTGlue.h"
|
|
||||||
#include "UTFStrings.h"
|
#include "UTFStrings.h"
|
||||||
#include "nsCRT.h"
|
#include "nsUnicharUtils.h"
|
||||||
|
#include "mozilla/HashFunctions.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ test_hashas16()
|
||||||
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
|
||||||
nsDependentCString str8(ValidStrings[i].m8);
|
nsDependentCString str8(ValidStrings[i].m8);
|
||||||
bool err;
|
bool err;
|
||||||
if (nsCRT::HashCode(ValidStrings[i].m16) !=
|
if (HashString(ValidStrings[i].m16) !=
|
||||||
nsCRT::HashCodeAsUTF16(str8.get(), str8.Length(), &err) ||
|
HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
|
||||||
err)
|
err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -162,8 +162,8 @@ test_hashas16()
|
||||||
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
|
||||||
nsDependentCString str8(Invalid8Strings[i].m8);
|
nsDependentCString str8(Invalid8Strings[i].m8);
|
||||||
bool err;
|
bool err;
|
||||||
if (nsCRT::HashCode(Invalid8Strings[i].m16) !=
|
if (HashString(Invalid8Strings[i].m16) !=
|
||||||
nsCRT::HashCodeAsUTF16(str8.get(), str8.Length(), &err) ||
|
HashUTF8AsUTF16(str8.get(), str8.Length(), &err) ||
|
||||||
err)
|
err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ test_hashas16()
|
||||||
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
|
||||||
nsDependentCString str8(Malformed8Strings[i]);
|
nsDependentCString str8(Malformed8Strings[i]);
|
||||||
bool err;
|
bool err;
|
||||||
if (nsCRT::HashCodeAsUTF16(str8.get(), str8.Length(), &err) != 0 ||
|
if (HashUTF8AsUTF16(str8.get(), str8.Length(), &err) != 0 ||
|
||||||
!err)
|
!err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче