Bug 1418156 - Don't zero newly added PrefHashEntrys. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 17 Nov 2017 13:30:38 +1100
changeset 699353 bae7d47a35523ff4dd52d5435c9dd1e49052bf1a
parent 699351 d8c4ada252706e44441dd383b47aa697ba141bb7
child 699354 050456f87fee3e7fbe19d68405745f1c815c7376
child 699829 454883fc69ec760f4938dc37f3748545e5c045c5
push id89542
push usernnethercote@mozilla.com
push dateFri, 17 Nov 2017 02:31:06 +0000
reviewersglandium
bugs1418156
milestone59.0a1
Bug 1418156 - Don't zero newly added PrefHashEntrys. r=glandium They are guaranteed to be zeroed already by PLDHashTable. MozReview-Commit-ID: LBeGa9ABYc3
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -169,22 +169,16 @@ public:
   {
   }
 
   explicit PrefTypeFlags(PrefType aType)
     : mValue(AsInt(aType))
   {
   }
 
-  PrefTypeFlags& Reset()
-  {
-    mValue = AsInt(PrefType::Invalid);
-    return *this;
-  }
-
   bool IsTypeValid() const { return !IsPrefType(PrefType::Invalid); }
   bool IsTypeString() const { return IsPrefType(PrefType::String); }
   bool IsTypeInt() const { return IsPrefType(PrefType::Int); }
   bool IsTypeBool() const { return IsPrefType(PrefType::Bool); }
   bool IsPrefType(PrefType type) const { return GetPrefType() == type; }
 
   void SetPrefType(PrefType aType)
   {
@@ -761,23 +755,20 @@ pref_SetPref(const char* aKey,
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   auto pref = static_cast<PrefHashEntry*>(gHashTable->Add(aKey, fallible));
   if (!pref) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  // New entry, need to initialize.
   if (!pref->mKey) {
-    // Initialize the pref entry.
-    pref->mPrefFlags.Reset().SetPrefType(aType);
+    // New (zeroed) entry. Initialize it.
+    pref->mPrefFlags.SetPrefType(aType);
     pref->mKey = ArenaStrdup(aKey, gPrefNameArena);
-    memset(&pref->mDefaultValue, 0, sizeof(pref->mDefaultValue));
-    memset(&pref->mUserValue, 0, sizeof(pref->mUserValue));
 
   } else if (pref->mPrefFlags.HasDefaultValue() &&
              !pref->mPrefFlags.IsPrefType(aType)) {
     NS_WARNING(
       nsPrintfCString(
         "Ignoring attempt to overwrite value of default pref %s (type %s) with "
         "the wrong type (%s)!",
         aKey,