Bug 1181445 (part 11) - Use nsBaseHashTable::Iterator in xpcom/glue/. r=froydnj.

--HG--
extra : rebase_source : 5b6fe9813c08627f626fa8da66a8e724baa274aa
This commit is contained in:
Nicholas Nethercote 2015-07-09 16:54:59 -07:00
parent 70347ce8c5
commit d367971294
3 changed files with 12 additions and 38 deletions

View File

@ -75,28 +75,21 @@ public:
mObserver = new nsCategoryObserver(mCategoryName.get());
}
mObserver->GetHash().EnumerateRead(EntriesToArray, &aResult);
for (auto iter = mObserver->GetHash().Iter(); !iter.Done(); iter.Next()) {
nsISupports* entry = iter.GetUserData();
nsCOMPtr<T> service = do_QueryInterface(entry);
if (service) {
aResult.AppendObject(service);
}
}
}
private:
// Not to be implemented
nsCategoryCache(const nsCategoryCache<T>&);
static PLDHashOperator EntriesToArray(const nsACString& aKey,
nsISupports* aEntry, void* aArg)
{
nsCOMArray<T>& entries = *static_cast<nsCOMArray<T>*>(aArg);
nsCOMPtr<T> service = do_QueryInterface(aEntry);
if (service) {
entries.AppendObject(service);
}
return PL_DHASH_NEXT;
}
nsCString mCategoryName;
nsRefPtr<nsCategoryObserver> mObserver;
};
#endif

View File

@ -299,24 +299,14 @@ nsINIParser::GetString(const char* aSection, const char* aKey,
return NS_ERROR_FAILURE;
}
PLDHashOperator
nsINIParser::GetSectionsCB(const char* aKey, INIValue* aData,
void* aClosure)
{
GSClosureStruct* cs = reinterpret_cast<GSClosureStruct*>(aClosure);
return cs->usercb(aKey, cs->userclosure) ? PL_DHASH_NEXT : PL_DHASH_STOP;
}
nsresult
nsINIParser::GetSections(INISectionCallback aCB, void* aClosure)
{
GSClosureStruct gs = {
aCB,
aClosure
};
mSections.EnumerateRead(GetSectionsCB, &gs);
for (auto iter = mSections.Iter(); !iter.Done(); iter.Next()) {
if (!aCB(iter.GetKey(), aClosure)) {
break;
}
}
return NS_OK;
}

View File

@ -109,19 +109,10 @@ private:
nsAutoPtr<INIValue> next;
};
struct GSClosureStruct
{
INISectionCallback usercb;
void* userclosure;
};
nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
nsAutoArrayPtr<char> mFileContents;
nsresult InitFromFILE(FILE* aFd);
static PLDHashOperator GetSectionsCB(const char* aKey,
INIValue* aData, void* aClosure);
};
#endif /* nsINIParser_h__ */