Bug 1435329 Improve the HashKey function in the Resist Fingerprinting Component r?froydnj
While we could not cut the order of the inputs over directly to the AddToHash methods
(because AddToHash(string) does not exist) - we could rearrange them and then not need
to build a temporary string.
MozReview-Commit-ID: 6At4MQ0KotE
--- a/toolkit/components/resistfingerprinting/nsRFPService.h
+++ b/toolkit/components/resistfingerprinting/nsRFPService.h
@@ -124,25 +124,21 @@ public:
static KeyTypePointer KeyToPointer(KeyType aKey)
{
return &aKey;
}
static PLDHashNumber HashKey(KeyTypePointer aKey)
{
- nsAutoString temp;
- temp.AppendInt(aKey->mLang);
- temp.Append('|');
- temp.AppendInt(aKey->mRegion);
- temp.Append('|');
- temp.AppendInt(aKey->mKeyIdx);
- temp.Append('|');
- temp.Append(aKey->mKey);
- return mozilla::HashString(temp);
+ PLDHashNumber hash = mozilla::HashString(aKey->mKey);
+ return mozilla::AddToHash(hash,
+ aKey->mRegion,
+ aKey->mKeyIdx,
+ aKey->mLang);
}
enum { ALLOW_MEMMOVE = true };
KeyboardLangs mLang;
KeyboardRegions mRegion;
KeyNameIndexType mKeyIdx;
nsString mKey;