Bug 1186794 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in embedding/ with iterators. r=bz.
Also make mGroupNames const to avoid a cast.
This commit is contained in:
@@ -27,14 +27,12 @@ public:
|
||||
protected:
|
||||
virtual ~nsGroupsEnumerator();
|
||||
|
||||
static PLDHashOperator HashEnum(const nsACString& aKey,
|
||||
nsTArray<nsCString>* aData, void* aClosure);
|
||||
nsresult Initialize();
|
||||
|
||||
protected:
|
||||
nsControllerCommandGroup::GroupsHashtable& mHashTable;
|
||||
int32_t mIndex;
|
||||
char** mGroupNames; // array of pointers to char16_t* in the hash table
|
||||
const char** mGroupNames; // array of pointers to char16_t* in the hash table
|
||||
bool mInitted;
|
||||
};
|
||||
|
||||
@@ -92,7 +90,7 @@ nsGroupsEnumerator::GetNext(nsISupports** aResult)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
char* thisGroupName = mGroupNames[mIndex];
|
||||
const char* thisGroupName = mGroupNames[mIndex];
|
||||
|
||||
nsCOMPtr<nsISupportsCString> supportsString =
|
||||
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
|
||||
@@ -104,18 +102,6 @@ nsGroupsEnumerator::GetNext(nsISupports** aResult)
|
||||
return CallQueryInterface(supportsString, aResult);
|
||||
}
|
||||
|
||||
/* static */
|
||||
/* return false to stop */
|
||||
PLDHashOperator
|
||||
nsGroupsEnumerator::HashEnum(const nsACString& aKey, nsTArray<nsCString>* aData,
|
||||
void* aClosure)
|
||||
{
|
||||
nsGroupsEnumerator* groupsEnum = static_cast<nsGroupsEnumerator*>(aClosure);
|
||||
groupsEnum->mGroupNames[groupsEnum->mIndex] = (char*)aKey.Data();
|
||||
groupsEnum->mIndex++;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGroupsEnumerator::Initialize()
|
||||
{
|
||||
@@ -123,13 +109,16 @@ nsGroupsEnumerator::Initialize()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mGroupNames = new char*[mHashTable.Count()];
|
||||
mGroupNames = new const char*[mHashTable.Count()];
|
||||
if (!mGroupNames) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mIndex = 0;
|
||||
mHashTable.EnumerateRead(HashEnum, this);
|
||||
for (auto iter = mHashTable.Iter(); !iter.Done(); iter.Next()) {
|
||||
mGroupNames[mIndex] = iter.Key().Data();
|
||||
mIndex++;
|
||||
}
|
||||
|
||||
mIndex = -1;
|
||||
mInitted = true;
|
||||
|
||||
Reference in New Issue
Block a user