Bug 1412718 (part 1) - Inline and remove PREF_DeleteBranch(). r=glandium. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 01 Nov 2017 07:59:40 +1100
changeset 689667 fa13eb8be2a088b717d834686d60b4eea6b1df4d
parent 688553 5c906f68ee713d8dcf039b5617901035dfd69471
child 689668 c6788cbed5c4b932eb5b4119c407aea538cb1799
push id87084
push usernnethercote@mozilla.com
push dateTue, 31 Oct 2017 21:31:54 +0000
reviewersglandium
bugs1412718
milestone58.0a1
Bug 1412718 (part 1) - Inline and remove PREF_DeleteBranch(). r=glandium. It has a single call site. MozReview-Commit-ID: BH7GuipEgl
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -780,58 +780,16 @@ PREF_GetBoolPref(const char* aPrefName, 
       *aValueOut = pref->mUserPref.mBoolVal;
       rv = NS_OK;
     }
   }
 
   return rv;
 }
 
-// Delete a branch of the tree.
-static nsresult
-PREF_DeleteBranch(const char* aBranchName)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  size_t len = strlen(aBranchName);
-
-  if (!gHashTable) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
-  // The following check insures that if the branch name already has a "." at
-  // the end, we don't end up with a "..". This fixes an incompatibility
-  // between nsIPref, which needs the period added, and nsIPrefBranch which
-  // does not. When nsIPref goes away this function should be fixed to never
-  // add the period at all.
-  nsAutoCString branch_dot(aBranchName);
-  if (len > 1 && aBranchName[len - 1] != '.') {
-    branch_dot += '.';
-  }
-
-  // Delete a branch. Used for deleting mime types.
-  const char* to_delete = branch_dot.get();
-  MOZ_ASSERT(to_delete);
-  len = strlen(to_delete);
-  for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
-    auto entry = static_cast<PrefHashEntry*>(iter.Get());
-
-    // Note: if we're deleting "ldap" then we want to delete "ldap.xxx" and
-    // "ldap" (if such a leaf node exists) but not "ldap_1.xxx".
-    if (PL_strncmp(entry->mKey, to_delete, len) == 0 ||
-        (len - 1 == strlen(entry->mKey) &&
-         PL_strncmp(entry->mKey, to_delete, len - 1) == 0)) {
-      iter.Remove();
-    }
-  }
-
-  Preferences::HandleDirty();
-  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;
   }
 
@@ -2848,18 +2806,54 @@ nsPrefBranch::ResetBranch(const char* aS
 }
 
 NS_IMETHODIMP
 nsPrefBranch::DeleteBranch(const char* aStartingAt)
 {
   ENSURE_MAIN_PROCESS("DeleteBranch", aStartingAt);
   NS_ENSURE_ARG(aStartingAt);
 
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (!gHashTable) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
+
   const PrefName& pref = GetPrefName(aStartingAt);
-  return PREF_DeleteBranch(pref.get());
+  const char* branchName = pref.get();
+  size_t len = strlen(branchName);
+
+  // The following check insures that if the branch name already has a "." at
+  // the end, we don't end up with a "..". This fixes an incompatibility
+  // between nsIPref, which needs the period added, and nsIPrefBranch which
+  // does not. When nsIPref goes away this function should be fixed to never
+  // add the period at all.
+  nsAutoCString branch_dot(branchName);
+  if (len > 1 && branchName[len - 1] != '.') {
+    branch_dot += '.';
+  }
+
+  // Delete a branch. Used for deleting mime types.
+  const char* to_delete = branch_dot.get();
+  MOZ_ASSERT(to_delete);
+  len = strlen(to_delete);
+  for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
+    auto entry = static_cast<PrefHashEntry*>(iter.Get());
+
+    // Note: if we're deleting "ldap" then we want to delete "ldap.xxx" and
+    // "ldap" (if such a leaf node exists) but not "ldap_1.xxx".
+    if (PL_strncmp(entry->mKey, to_delete, len) == 0 ||
+        (len - 1 == strlen(entry->mKey) &&
+         PL_strncmp(entry->mKey, to_delete, len - 1) == 0)) {
+      iter.Remove();
+    }
+  }
+
+  Preferences::HandleDirty();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetChildList(const char* aStartingAt,
                            uint32_t* aCount,
                            char*** aChildArray)
 {
   char** outArray;