Bug 1435329 Improve the HashKey function in the Resist Fingerprinting Component r?froydnj draft
authorTom Ritter <tom@mozilla.com>
Sun, 18 Feb 2018 23:19:02 -0600
changeset 757104 0eff83fac23e95d6e3d366f979555b174b07a7f9
parent 756881 ce24b5d47b141093e6cc55c635bbf376a75a15b9
push id99660
push userbmo:tom@mozilla.com
push dateMon, 19 Feb 2018 22:34:37 +0000
reviewersfroydnj
bugs1435329
milestone60.0a1
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
toolkit/components/resistfingerprinting/nsRFPService.h
--- 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;