Bug 1557501. Stop using [array] in nsIPrefBranch. r=njn

Differential Revision: https://phabricator.services.mozilla.com/D34032

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-06-07 01:01:12 +00:00
Родитель 6b74e0f7de
Коммит 89baee69d9
7 изменённых файлов: 40 добавлений и 72 удалений

Просмотреть файл

@ -2376,12 +2376,11 @@ bool gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics() {
static const char kFontNamePrefix[] = "font.name."; static const char kFontNamePrefix[] = "font.name.";
bool prefFontsUseOnlyGenerics = true; bool prefFontsUseOnlyGenerics = true;
uint32_t count; nsTArray<nsCString> names;
char** names; nsresult rv =
nsresult rv = Preferences::GetRootBranch()->GetChildList(kFontNamePrefix, Preferences::GetRootBranch()->GetChildList(kFontNamePrefix, names);
&count, &names); if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv) && count) { for (auto& name : names) {
for (size_t i = 0; i < count; i++) {
// Check whether all font.name prefs map to generic keywords // Check whether all font.name prefs map to generic keywords
// and that the pref name and keyword match. // and that the pref name and keyword match.
// Ex: font.name.serif.ar ==> "serif" (ok) // Ex: font.name.serif.ar ==> "serif" (ok)
@ -2393,12 +2392,13 @@ bool gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics() {
// font.name-list.serif.ar ==> "Something, serif" // font.name-list.serif.ar ==> "Something, serif"
// (return false) // (return false)
nsDependentCString prefName(names[i] + ArrayLength(kFontNamePrefix) - 1); nsDependentCSubstring prefName =
Substring(name, ArrayLength(kFontNamePrefix) - 1);
nsCCharSeparatedTokenizer tokenizer(prefName, '.'); nsCCharSeparatedTokenizer tokenizer(prefName, '.');
const nsDependentCSubstring& generic = tokenizer.nextToken(); const nsDependentCSubstring& generic = tokenizer.nextToken();
const nsDependentCSubstring& langGroup = tokenizer.nextToken(); const nsDependentCSubstring& langGroup = tokenizer.nextToken();
nsAutoCString fontPrefValue; nsAutoCString fontPrefValue;
Preferences::GetCString(names[i], fontPrefValue); Preferences::GetCString(name.get(), fontPrefValue);
if (fontPrefValue.IsEmpty()) { if (fontPrefValue.IsEmpty()) {
// The font name list may have two or more family names as comma // The font name list may have two or more family names as comma
// separated list. In such case, not matching with generic font // separated list. In such case, not matching with generic font
@ -2414,7 +2414,6 @@ bool gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics() {
break; break;
} }
} }
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, names);
} }
return prefFontsUseOnlyGenerics; return prefFontsUseOnlyGenerics;
} }

Просмотреть файл

@ -278,16 +278,15 @@ void nsHyphenationManager::LoadAliases() {
if (!prefRootBranch) { if (!prefRootBranch) {
return; return;
} }
uint32_t prefCount; nsTArray<nsCString> prefNames;
char** prefNames; nsresult rv =
nsresult rv = prefRootBranch->GetChildList(kIntlHyphenationAliasPrefix, prefRootBranch->GetChildList(kIntlHyphenationAliasPrefix, prefNames);
&prefCount, &prefNames); if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv) && prefCount > 0) { for (auto& prefName : prefNames) {
for (uint32_t i = 0; i < prefCount; ++i) {
nsAutoCString value; nsAutoCString value;
rv = Preferences::GetCString(prefNames[i], value); rv = Preferences::GetCString(prefName.get(), value);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
nsAutoCString alias(prefNames[i]); nsAutoCString alias(prefName);
alias.Cut(0, sizeof(kIntlHyphenationAliasPrefix) - 1); alias.Cut(0, sizeof(kIntlHyphenationAliasPrefix) - 1);
ToLowerCase(alias); ToLowerCase(alias);
ToLowerCase(value); ToLowerCase(value);
@ -296,6 +295,5 @@ void nsHyphenationManager::LoadAliases() {
mHyphAliases.Put(aliasAtom, valueAtom); mHyphAliases.Put(aliasAtom, valueAtom);
} }
} }
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefNames);
} }
} }

Просмотреть файл

@ -2575,24 +2575,15 @@ nsPrefBranch::DeleteBranch(const char* aStartingAt) {
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPrefBranch::GetChildList(const char* aStartingAt, uint32_t* aCount, nsPrefBranch::GetChildList(const char* aStartingAt,
char*** aChildArray) { nsTArray<nsCString>& aChildArray) {
char** outArray;
int32_t numPrefs;
int32_t dwIndex;
AutoTArray<nsCString, 32> prefArray;
NS_ENSURE_ARG(aStartingAt); NS_ENSURE_ARG(aStartingAt);
NS_ENSURE_ARG_POINTER(aCount);
NS_ENSURE_ARG_POINTER(aChildArray);
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
*aChildArray = nullptr;
*aCount = 0;
// This will contain a list of all the pref name strings. Allocated on the // This will contain a list of all the pref name strings. Allocated on the
// stack for speed. // stack for speed.
AutoTArray<nsCString, 32> prefArray;
const PrefName& parent = GetPrefName(aStartingAt); const PrefName& parent = GetPrefName(aStartingAt);
size_t parentLen = parent.Length(); size_t parentLen = parent.Length();
@ -2604,22 +2595,12 @@ nsPrefBranch::GetChildList(const char* aStartingAt, uint32_t* aCount,
// Now that we've built up the list, run the callback on all the matching // Now that we've built up the list, run the callback on all the matching
// elements. // elements.
numPrefs = prefArray.Length(); aChildArray.SetCapacity(prefArray.Length());
for (auto& element : prefArray) {
if (numPrefs) { // we need to lop off mPrefRoot in case the user is planning to pass this
outArray = (char**)moz_xmalloc(numPrefs * sizeof(char*)); // back to us because if they do we are going to add mPrefRoot again.
aChildArray.AppendElement(Substring(element, mPrefRoot.Length()));
for (dwIndex = 0; dwIndex < numPrefs; ++dwIndex) {
// we need to lop off mPrefRoot in case the user is planning to pass this
// back to us because if they do we are going to add mPrefRoot again.
const nsCString& element = prefArray[dwIndex];
outArray[dwIndex] =
(char*)moz_xmemdup(element.get() + mPrefRoot.Length(),
element.Length() - mPrefRoot.Length() + 1);
}
*aChildArray = outArray;
} }
*aCount = numPrefs;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -336,8 +336,7 @@ interface nsIPrefBranch : nsISupports
* @param aStartingAt The point on the branch at which to start enumerating * @param aStartingAt The point on the branch at which to start enumerating
* the child preferences. Pass in "" to enumerate all * the child preferences. Pass in "" to enumerate all
* preferences referenced by this branch. * preferences referenced by this branch.
* @param aCount Receives the number of elements in the array. * @return The array of child preferences.
* @param aChildArray Receives the array of child preferences.
* *
* @note * @note
* This method can be called on either a default or user branch but, in * This method can be called on either a default or user branch but, in
@ -345,9 +344,7 @@ interface nsIPrefBranch : nsISupports
* *
* @throws Error The preference(s) do not exist or an error occurred. * @throws Error The preference(s) do not exist or an error occurred.
*/ */
void getChildList(in string aStartingAt, Array<ACString> getChildList(in string aStartingAt);
[optional] out unsigned long aCount,
[array, size_is(aCount), retval] out string aChildArray);
/** /**
* Called to reset all of the preferences referenced by this branch to their * Called to reset all of the preferences referenced by this branch to their

Просмотреть файл

@ -828,15 +828,13 @@ nsresult nsUrlClassifierUtils::ReadProvidersFromPrefs(ProviderDictType& aDict) {
// We've got a pref branch for "browser.safebrowsing.provider.". // We've got a pref branch for "browser.safebrowsing.provider.".
// Enumerate all children prefs and parse providers. // Enumerate all children prefs and parse providers.
uint32_t childCount; nsTArray<nsCString> childArray;
char** childArray; rv = prefBranch->GetChildList("", childArray);
rv = prefBranch->GetChildList("", &childCount, &childArray);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Collect providers from childArray. // Collect providers from childArray.
nsTHashtable<nsCStringHashKey> providers; nsTHashtable<nsCStringHashKey> providers;
for (uint32_t i = 0; i < childCount; i++) { for (auto& child : childArray) {
nsCString child(childArray[i]);
auto dotPos = child.FindChar('.'); auto dotPos = child.FindChar('.');
if (dotPos < 0) { if (dotPos < 0) {
continue; continue;
@ -846,7 +844,6 @@ nsresult nsUrlClassifierUtils::ReadProvidersFromPrefs(ProviderDictType& aDict) {
providers.PutEntry(provider); providers.PutEntry(provider);
} }
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray);
// Now we have all providers. Check which one owns |aTableName|. // Now we have all providers. Check which one owns |aTableName|.
// e.g. The owning lists of provider "google" is defined in // e.g. The owning lists of provider "google" is defined in

Просмотреть файл

@ -32,7 +32,7 @@ const prefs = [
var providers = {}; var providers = {};
var branch = SpecialPowers.Services.prefs.getBranch("browser.safebrowsing.provider."); var branch = SpecialPowers.Services.prefs.getBranch("browser.safebrowsing.provider.");
var children = branch.getChildList("", {}); var children = branch.getChildList("");
for (var child of children) { for (var child of children) {
var prefComponents = child.split("."); var prefComponents = child.split(".");

Просмотреть файл

@ -35,16 +35,14 @@ NS_IMPL_ISUPPORTS(LogModulePrefWatcher, nsIObserver)
* pref to false, or use the MOZ_LOG_FILE and MOZ_LOG_MODULES env vars. * pref to false, or use the MOZ_LOG_FILE and MOZ_LOG_MODULES env vars.
*/ */
static void ResetExistingPrefs() { static void ResetExistingPrefs() {
uint32_t count; nsTArray<nsCString> names;
char** names; nsresult rv =
nsresult rv = Preferences::GetRootBranch()->GetChildList(kLoggingPrefPrefix, Preferences::GetRootBranch()->GetChildList(kLoggingPrefPrefix, names);
&count, &names); if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv) && count) { for (auto& name : names) {
for (size_t i = 0; i < count; i++) {
// Clearing the pref will cause it to reload, thus resetting the log level // Clearing the pref will cause it to reload, thus resetting the log level
Preferences::ClearUser(names[i]); Preferences::ClearUser(name.get());
} }
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, names);
} }
} }
@ -112,14 +110,12 @@ static void LoadExistingPrefs() {
return; return;
} }
uint32_t count; nsTArray<nsCString> names;
char** names; nsresult rv = root->GetChildList(kLoggingPrefPrefix, names);
nsresult rv = root->GetChildList(kLoggingPrefPrefix, &count, &names); if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv) && count) { for (auto& name : names) {
for (size_t i = 0; i < count; i++) { LoadPrefValue(name.get());
LoadPrefValue(names[i]);
} }
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, names);
} }
} }