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
--- 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(