Bug 1418156 - Don't zero newly added PrefHashEntrys. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 17 Nov 2017 12:15:02 +1100
changeset 699337 ad20b2a431756209f996d9300fc0567cc79ee359
parent 699336 1b6ce144c6ef056ba9a8d8c848339ef17d6cb5e8
child 699338 58e954057ce93e3a71a8ea7d72e9a59a6346c6f2
push id89536
push usernnethercote@mozilla.com
push dateFri, 17 Nov 2017 01:25:26 +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,