Bug 1416638 - Inline and remove PREF_Get*(). r=glandium.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 14 Nov 2017 19:06:02 +1100
changeset 436514 33a809bfb84082255572bb5c719603f9830645eb
parent 436513 6a5f54a05259edee7d7b4f9205bef9e8d240049f
child 436590 dca8caef56e168fd94d809eca6fafb48eb4bf25d
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersglandium
bugs1416638
milestone59.0a1
Bug 1416638 - Inline and remove PREF_Get*(). r=glandium. MozReview-Commit-ID: CiCKpihJJJF
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -527,107 +527,16 @@ PREF_HasUserPref(const char* aPrefName)
   if (!gHashTable) {
     return false;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   return pref && pref->mPrefFlags.HasUserValue();
 }
 
-static nsresult
-PREF_GetCStringPref(const char* aPrefName,
-                    nsACString& aValueOut,
-                    bool aGetDefault)
-{
-  aValueOut.SetIsVoid(true);
-
-  if (!gHashTable) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
-  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
-  if (!pref || !pref->mPrefFlags.IsTypeString()) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  const char* stringVal = nullptr;
-  if (aGetDefault || pref->mPrefFlags.IsLocked() ||
-      !pref->mPrefFlags.HasUserValue()) {
-
-    // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
-      return NS_ERROR_UNEXPECTED;
-    }
-    stringVal = pref->mDefaultPref.mStringVal;
-  } else {
-    stringVal = pref->mUserPref.mStringVal;
-  }
-
-  if (!stringVal) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  aValueOut = stringVal;
-  return NS_OK;
-}
-
-static nsresult
-PREF_GetIntPref(const char* aPrefName, int32_t* aValueOut, bool aGetDefault)
-{
-  if (!gHashTable) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
-  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
-  if (!pref || !pref->mPrefFlags.IsTypeInt()) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  if (aGetDefault || pref->mPrefFlags.IsLocked() ||
-      !pref->mPrefFlags.HasUserValue()) {
-
-    // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
-      return NS_ERROR_UNEXPECTED;
-    }
-    *aValueOut = pref->mDefaultPref.mIntVal;
-  } else {
-    *aValueOut = pref->mUserPref.mIntVal;
-  }
-
-  return NS_OK;
-}
-
-static nsresult
-PREF_GetBoolPref(const char* aPrefName, bool* aValueOut, bool aGetDefault)
-{
-  if (!gHashTable) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
-  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
-  if (!pref || !pref->mPrefFlags.IsTypeBool()) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  if (aGetDefault || pref->mPrefFlags.IsLocked() ||
-      !pref->mPrefFlags.HasUserValue()) {
-
-    // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
-      return NS_ERROR_UNEXPECTED;
-    }
-    *aValueOut = pref->mDefaultPref.mBoolVal;
-  } else {
-    *aValueOut = pref->mUserPref.mBoolVal;
-  }
-
-  return NS_OK;
-}
-
 // Clears the given pref (reverts it to its default value).
 static nsresult
 PREF_ClearUserPref(const char* aPrefName)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
@@ -2114,17 +2023,17 @@ nsPrefBranch::GetBoolPrefWithDefault(con
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetBoolPref(const char* aPrefName, bool* aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
 
   const PrefName& pref = GetPrefName(aPrefName);
-  return PREF_GetBoolPref(pref.get(), aRetVal, mKind == PrefValueKind::Default);
+  return Preferences::GetBool(pref.get(), aRetVal, mKind);
 }
 
 NS_IMETHODIMP
 nsPrefBranch::SetBoolPref(const char* aPrefName, bool aValue)
 {
   NS_ENSURE_ARG(aPrefName);
 
   const PrefName& pref = GetPrefName(aPrefName);
@@ -2176,19 +2085,19 @@ nsPrefBranch::GetCharPrefWithDefault(con
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetCharPref(const char* aPrefName, nsACString& aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
+
   const PrefName& pref = GetPrefName(aPrefName);
-  return PREF_GetCStringPref(
-    pref.get(), aRetVal, mKind == PrefValueKind::Default);
+  return Preferences::GetCString(pref.get(), aRetVal, mKind);
 }
 
 NS_IMETHODIMP
 nsPrefBranch::SetCharPref(const char* aPrefName, const nsACString& aValue)
 {
   nsresult rv = CheckSanityOfStringLength(aPrefName, aValue);
   if (NS_FAILED(rv)) {
     return rv;
@@ -2254,17 +2163,17 @@ nsPrefBranch::GetIntPrefWithDefault(cons
   return rv;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetIntPref(const char* aPrefName, int32_t* aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
   const PrefName& pref = GetPrefName(aPrefName);
-  return PREF_GetIntPref(pref.get(), aRetVal, mKind == PrefValueKind::Default);
+  return Preferences::GetInt(pref.get(), aRetVal, mKind);
 }
 
 NS_IMETHODIMP
 nsPrefBranch::SetIntPref(const char* aPrefName, int32_t aValue)
 {
   NS_ENSURE_ARG(aPrefName);
 
   const PrefName& pref = GetPrefName(aPrefName);
@@ -2868,17 +2777,18 @@ nsPrefBranch::RemoveExpiredCallback(Pref
 
 nsresult
 nsPrefBranch::GetDefaultFromPropertiesFile(const char* aPrefName,
                                            nsAString& aReturn)
 {
   // The default value contains a URL to a .properties file.
 
   nsAutoCString propertyFileURL;
-  nsresult rv = PREF_GetCStringPref(aPrefName, propertyFileURL, true);
+  nsresult rv =
+    Preferences::GetCString(aPrefName, propertyFileURL, PrefValueKind::Default);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   if (!bundleService) {
     return NS_ERROR_FAILURE;
@@ -3464,18 +3374,18 @@ Preferences::GetInstanceForService()
     }
     delete gInitPrefs;
     gInitPrefs = nullptr;
 
   } else {
     // Check if there is a deployment configuration file. If so, set up the
     // pref config machinery, which will actually read the file.
     nsAutoCString lockFileName;
-    nsresult rv =
-      PREF_GetCStringPref("general.config.filename", lockFileName, false);
+    nsresult rv = Preferences::GetCString(
+      "general.config.filename", lockFileName, PrefValueKind::User);
     if (NS_SUCCEEDED(rv)) {
       NS_CreateServicesFromCategory(
         "pref-config-startup",
         static_cast<nsISupports*>(static_cast<void*>(sPreferences)),
         "pref-config-startup");
     }
 
     nsCOMPtr<nsIObserverService> observerService =
@@ -4481,64 +4391,122 @@ Preferences::InitInitialObjects()
 // Static utilities
 //----------------------------------------------------------------------------
 
 /* static */ nsresult
 Preferences::GetBool(const char* aPrefName, bool* aResult, PrefValueKind aKind)
 {
   NS_PRECONDITION(aResult, "aResult must not be NULL");
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_GetBoolPref(aPrefName, aResult, aKind == PrefValueKind::Default);
+
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
+  if (!pref || !pref->mPrefFlags.IsTypeBool()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
+      !pref->mPrefFlags.HasUserValue()) {
+
+    // Do we have a default?
+    if (!pref->mPrefFlags.HasDefault()) {
+      return NS_ERROR_UNEXPECTED;
+    }
+    *aResult = pref->mDefaultPref.mBoolVal;
+  } else {
+    *aResult = pref->mUserPref.mBoolVal;
+  }
+
+  return NS_OK;
 }
 
 /* static */ nsresult
 Preferences::GetInt(const char* aPrefName,
                     int32_t* aResult,
                     PrefValueKind aKind)
 {
   NS_PRECONDITION(aResult, "aResult must not be NULL");
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_GetIntPref(aPrefName, aResult, aKind == PrefValueKind::Default);
+
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
+  if (!pref || !pref->mPrefFlags.IsTypeInt()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
+      !pref->mPrefFlags.HasUserValue()) {
+
+    // Do we have a default?
+    if (!pref->mPrefFlags.HasDefault()) {
+      return NS_ERROR_UNEXPECTED;
+    }
+    *aResult = pref->mDefaultPref.mIntVal;
+  } else {
+    *aResult = pref->mUserPref.mIntVal;
+  }
+
+  return NS_OK;
 }
 
 /* static */ nsresult
 Preferences::GetFloat(const char* aPrefName,
                       float* aResult,
                       PrefValueKind aKind)
 {
   NS_PRECONDITION(aResult, "aResult must not be NULL");
-  NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
+
   nsAutoCString result;
-  nsresult rv =
-    PREF_GetCStringPref(aPrefName, result, aKind == PrefValueKind::Default);
+  nsresult rv = Preferences::GetCString(aPrefName, result, aKind);
   if (NS_SUCCEEDED(rv)) {
     *aResult = result.ToFloat(&rv);
   }
   return rv;
 }
 
 /* static */ nsresult
 Preferences::GetCString(const char* aPrefName,
                         nsACString& aResult,
                         PrefValueKind aKind)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_GetCStringPref(
-    aPrefName, aResult, aKind == PrefValueKind::Default);
+
+  aResult.SetIsVoid(true);
+
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
+  if (!pref || !pref->mPrefFlags.IsTypeString()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  const char* stringVal = nullptr;
+  if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
+      !pref->mPrefFlags.HasUserValue()) {
+
+    // Do we have a default?
+    if (!pref->mPrefFlags.HasDefault()) {
+      return NS_ERROR_UNEXPECTED;
+    }
+    stringVal = pref->mDefaultPref.mStringVal;
+  } else {
+    stringVal = pref->mUserPref.mStringVal;
+  }
+
+  if (!stringVal) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  aResult = stringVal;
+  return NS_OK;
 }
 
 /* static */ nsresult
 Preferences::GetString(const char* aPrefName,
                        nsAString& aResult,
                        PrefValueKind aKind)
 {
-  NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   nsAutoCString result;
-  nsresult rv =
-    PREF_GetCStringPref(aPrefName, result, aKind == PrefValueKind::Default);
+  nsresult rv = Preferences::GetCString(aPrefName, result, aKind);
   if (NS_SUCCEEDED(rv)) {
     CopyUTF8toUTF16(result, aResult);
   }
   return rv;
 }
 
 /* static */ nsresult
 Preferences::GetLocalizedCString(const char* aPrefName,