зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1411480 (attempt 2) - Simplify pref_HashPref()'s workings. r=glandium.
First, the patch removes the return values from PrefTypeFlags::Set*(). They allow chained calls, but they're barely used and they just make the code harder to read. Second, the patch changes pref_SetValue() to not modify and return the pref flags. It's clearer if the flags changing is done separately. This requires passing pref_SetValue() the old type instead of the flags. MozReview-Commit-ID: HZVS2TIlBIY --HG-- extra : rebase_source : 6638244214cda15ceae5a1930659aed434d8261b
This commit is contained in:
Родитель
81afb7d3f2
Коммит
bfdd7e8e70
|
@ -190,10 +190,9 @@ public:
|
||||||
bool IsTypeBool() const { return IsPrefType(PrefType::Bool); }
|
bool IsTypeBool() const { return IsPrefType(PrefType::Bool); }
|
||||||
bool IsPrefType(PrefType type) const { return GetPrefType() == type; }
|
bool IsPrefType(PrefType type) const { return GetPrefType() == type; }
|
||||||
|
|
||||||
PrefTypeFlags& SetPrefType(PrefType aType)
|
void SetPrefType(PrefType aType)
|
||||||
{
|
{
|
||||||
mValue = mValue - AsInt(GetPrefType()) + AsInt(aType);
|
mValue = mValue - AsInt(GetPrefType()) + AsInt(aType);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrefType GetPrefType() const
|
PrefType GetPrefType() const
|
||||||
|
@ -204,39 +203,35 @@ public:
|
||||||
|
|
||||||
bool HasDefault() const { return mValue & PREF_FLAG_HAS_DEFAULT; }
|
bool HasDefault() const { return mValue & PREF_FLAG_HAS_DEFAULT; }
|
||||||
|
|
||||||
PrefTypeFlags& SetHasDefault(bool aSetOrUnset)
|
void SetHasDefault(bool aSetOrUnset)
|
||||||
{
|
{
|
||||||
return SetFlag(PREF_FLAG_HAS_DEFAULT, aSetOrUnset);
|
SetFlag(PREF_FLAG_HAS_DEFAULT, aSetOrUnset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasStickyDefault() const { return mValue & PREF_FLAG_STICKY_DEFAULT; }
|
bool HasStickyDefault() const { return mValue & PREF_FLAG_STICKY_DEFAULT; }
|
||||||
|
|
||||||
PrefTypeFlags& SetHasStickyDefault(bool aSetOrUnset)
|
void SetHasStickyDefault(bool aSetOrUnset)
|
||||||
{
|
{
|
||||||
return SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset);
|
SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsLocked() const { return mValue & PREF_FLAG_LOCKED; }
|
bool IsLocked() const { return mValue & PREF_FLAG_LOCKED; }
|
||||||
|
|
||||||
PrefTypeFlags& SetLocked(bool aSetOrUnset)
|
void SetLocked(bool aSetOrUnset) { SetFlag(PREF_FLAG_LOCKED, aSetOrUnset); }
|
||||||
{
|
|
||||||
return SetFlag(PREF_FLAG_LOCKED, aSetOrUnset);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasUserValue() const { return mValue & PREF_FLAG_USERSET; }
|
bool HasUserValue() const { return mValue & PREF_FLAG_USERSET; }
|
||||||
|
|
||||||
PrefTypeFlags& SetHasUserValue(bool aSetOrUnset)
|
void SetHasUserValue(bool aSetOrUnset)
|
||||||
{
|
{
|
||||||
return SetFlag(PREF_FLAG_USERSET, aSetOrUnset);
|
SetFlag(PREF_FLAG_USERSET, aSetOrUnset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint16_t AsInt(PrefType aType) { return (uint16_t)aType; }
|
static uint16_t AsInt(PrefType aType) { return (uint16_t)aType; }
|
||||||
|
|
||||||
PrefTypeFlags& SetFlag(uint16_t aFlag, bool aSetOrUnset)
|
void SetFlag(uint16_t aFlag, bool aSetOrUnset)
|
||||||
{
|
{
|
||||||
mValue = aSetOrUnset ? mValue | aFlag : mValue & ~aFlag;
|
mValue = aSetOrUnset ? mValue | aFlag : mValue & ~aFlag;
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We pack both the value of type (PrefType) and flags into the same int. The
|
// We pack both the value of type (PrefType) and flags into the same int. The
|
||||||
|
@ -946,26 +941,23 @@ pref_ValueChanged(PrefValue aOldValue, PrefValue aNewValue, PrefType aType)
|
||||||
// Overwrite the type and value of an existing preference. Caller must ensure
|
// Overwrite the type and value of an existing preference. Caller must ensure
|
||||||
// that they are not changing the type of a preference that has a default
|
// that they are not changing the type of a preference that has a default
|
||||||
// value.
|
// value.
|
||||||
static PrefTypeFlags
|
static void
|
||||||
pref_SetValue(PrefValue* aExistingValue,
|
pref_SetValue(PrefValue* aExistingValue,
|
||||||
PrefTypeFlags aFlags,
|
PrefType aExistingType,
|
||||||
PrefValue aNewValue,
|
PrefValue aNewValue,
|
||||||
PrefType aNewType)
|
PrefType aNewType)
|
||||||
{
|
{
|
||||||
if (aFlags.IsTypeString() && aExistingValue->mStringVal) {
|
if (aExistingType == PrefType::String) {
|
||||||
free(const_cast<char*>(aExistingValue->mStringVal));
|
free(const_cast<char*>(aExistingValue->mStringVal));
|
||||||
}
|
}
|
||||||
|
|
||||||
aFlags.SetPrefType(aNewType);
|
if (aNewType == PrefType::String) {
|
||||||
if (aFlags.IsTypeString()) {
|
|
||||||
MOZ_ASSERT(aNewValue.mStringVal);
|
MOZ_ASSERT(aNewValue.mStringVal);
|
||||||
aExistingValue->mStringVal =
|
aExistingValue->mStringVal =
|
||||||
aNewValue.mStringVal ? moz_xstrdup(aNewValue.mStringVal) : nullptr;
|
aNewValue.mStringVal ? moz_xstrdup(aNewValue.mStringVal) : nullptr;
|
||||||
} else {
|
} else {
|
||||||
*aExistingValue = aNewValue;
|
*aExistingValue = aNewValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return aFlags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -1071,9 +1063,10 @@ pref_HashPref(const char* aKey,
|
||||||
// ?? change of semantics?
|
// ?? change of semantics?
|
||||||
if (pref_ValueChanged(pref->mDefaultPref, aValue, aType) ||
|
if (pref_ValueChanged(pref->mDefaultPref, aValue, aType) ||
|
||||||
!pref->mPrefFlags.HasDefault()) {
|
!pref->mPrefFlags.HasDefault()) {
|
||||||
pref->mPrefFlags =
|
pref_SetValue(
|
||||||
pref_SetValue(&pref->mDefaultPref, pref->mPrefFlags, aValue, aType)
|
&pref->mDefaultPref, pref->mPrefFlags.GetPrefType(), aValue, aType);
|
||||||
.SetHasDefault(true);
|
pref->mPrefFlags.SetPrefType(aType);
|
||||||
|
pref->mPrefFlags.SetHasDefault(true);
|
||||||
if (aFlags & kPrefStickyDefault) {
|
if (aFlags & kPrefStickyDefault) {
|
||||||
pref->mPrefFlags.SetHasStickyDefault(true);
|
pref->mPrefFlags.SetHasStickyDefault(true);
|
||||||
}
|
}
|
||||||
|
@ -1103,9 +1096,10 @@ pref_HashPref(const char* aKey,
|
||||||
} else if (!pref->mPrefFlags.HasUserValue() ||
|
} else if (!pref->mPrefFlags.HasUserValue() ||
|
||||||
!pref->mPrefFlags.IsPrefType(aType) ||
|
!pref->mPrefFlags.IsPrefType(aType) ||
|
||||||
pref_ValueChanged(pref->mUserPref, aValue, aType)) {
|
pref_ValueChanged(pref->mUserPref, aValue, aType)) {
|
||||||
pref->mPrefFlags =
|
pref_SetValue(
|
||||||
pref_SetValue(&pref->mUserPref, pref->mPrefFlags, aValue, aType)
|
&pref->mUserPref, pref->mPrefFlags.GetPrefType(), aValue, aType);
|
||||||
.SetHasUserValue(true);
|
pref->mPrefFlags.SetPrefType(aType);
|
||||||
|
pref->mPrefFlags.SetHasUserValue(true);
|
||||||
if (!pref->mPrefFlags.IsLocked()) {
|
if (!pref->mPrefFlags.IsLocked()) {
|
||||||
Preferences::HandleDirty();
|
Preferences::HandleDirty();
|
||||||
valueChanged = true;
|
valueChanged = true;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче