Bug 1394578 - Introduce PrefType::None. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 23 Nov 2017 16:35:38 +1100
changeset 702919 02d7f1b5af99ff2732e338c8c5834f48daaa9e58
parent 702910 624cc4ce298e9311b4580307543f86b2465fea54
child 702920 44ff75eac50fb4be5267dff3c52193a6346d8f66
child 703384 e2209017d344822fa829befc0f6b430ec8d32047
push id90629
push usernnethercote@mozilla.com
push dateFri, 24 Nov 2017 00:07:43 +0000
reviewersglandium
bugs1394578
milestone59.0a1
Bug 1394578 - Introduce PrefType::None. r=glandium And remove the type argument from PrefValue's constructor. This is needed for the next patch. MozReview-Commit-ID: Ls8hEU2uRQQ
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -118,16 +118,17 @@ typedef nsTArray<nsCString> PrefSaveData
 
 // 1 MB should be enough for everyone.
 static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
 // Actually, 4kb should be enough for everyone.
 static const uint32_t MAX_ADVISABLE_PREF_LENGTH = 4 * 1024;
 
 enum class PrefType : uint8_t
 {
+  None = 0, // only used when neither the default nor user value is set
   String = 1,
   Int = 2,
   Bool = 3,
 };
 
 union PrefValue {
   const char* mStringVal;
   int32_t mIntVal;
@@ -269,20 +270,20 @@ StrEscape(const char* aOriginal, nsCStri
   aResult.Append('"');
 }
 
 static ArenaAllocator<8192, 1> gPrefNameArena;
 
 class Pref : public PLDHashEntryHdr
 {
 public:
-  Pref(const char* aName, PrefType aType)
+  explicit Pref(const char* aName)
   {
     mName = ArenaStrdup(aName, gPrefNameArena);
-    SetType(aType);
+
     // We don't set the other fields because PLDHashTable always zeroes new
     // entries.
   }
 
   ~Pref()
   {
     // There's no need to free mName because it's allocated in memory owned by
     // gPrefNameArena.
@@ -756,17 +757,18 @@ pref_SetPref(const char* aPrefName,
 
   auto pref = static_cast<Pref*>(gHashTable->Add(aPrefName, fallible));
   if (!pref) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (!pref->Name()) {
     // New (zeroed) entry. Initialize it.
-    new (pref) Pref(aPrefName, aType);
+    new (pref) Pref(aPrefName);
+    pref->SetType(aType);
   }
 
   bool valueChanged = false, handleDirty = false;
   nsresult rv = pref->SetValue(
     aType, aKind, aValue, aIsSticky, aForceSet, &valueChanged, &handleDirty);
   if (NS_FAILED(rv)) {
     NS_WARNING(
       nsPrintfCString(