mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1181445 (part 13) - Use nsBaseHashTable::Iterator in xpcom/ds/. r=froydnj.
This commit is contained in:
parent
4d241772da
commit
e7e7541033
@ -114,18 +114,6 @@ nsSimpleProperty::GetValue(nsIVariant** aValue)
|
||||
|
||||
// end nsSimpleProperty
|
||||
|
||||
static PLDHashOperator
|
||||
PropertyHashToArrayFunc(const nsAString& aKey,
|
||||
nsIVariant* aData,
|
||||
void* aUserArg)
|
||||
{
|
||||
nsIMutableArray* propertyArray = static_cast<nsIMutableArray*>(aUserArg);
|
||||
nsSimpleProperty* sprop = new nsSimpleProperty(aKey, aData);
|
||||
propertyArray->AppendElement(sprop, false);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHashPropertyBagBase::GetEnumerator(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
@ -134,7 +122,12 @@ nsHashPropertyBagBase::GetEnumerator(nsISimpleEnumerator** aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mPropertyHash.EnumerateRead(PropertyHashToArrayFunc, propertyArray.get());
|
||||
for (auto iter = mPropertyHash.Iter(); !iter.Done(); iter.Next()) {
|
||||
const nsAString& key = iter.GetKey();
|
||||
nsIVariant* data = iter.GetUserData();
|
||||
nsSimpleProperty* sprop = new nsSimpleProperty(key, data);
|
||||
propertyArray->AppendElement(sprop, false);
|
||||
}
|
||||
|
||||
return NS_NewArrayEnumerator(aResult, propertyArray);
|
||||
}
|
||||
|
@ -65,28 +65,6 @@ nsProperties::Has(const char* prop, bool* result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
struct GetKeysEnumData
|
||||
{
|
||||
char** keys;
|
||||
uint32_t next;
|
||||
nsresult res;
|
||||
};
|
||||
|
||||
PLDHashOperator
|
||||
GetKeysEnumerate(const char* aKey, nsISupports* aData, void* aArg)
|
||||
{
|
||||
GetKeysEnumData* gkedp = (GetKeysEnumData*)aArg;
|
||||
gkedp->keys[gkedp->next] = strdup(aKey);
|
||||
|
||||
if (!gkedp->keys[gkedp->next]) {
|
||||
gkedp->res = NS_ERROR_OUT_OF_MEMORY;
|
||||
return PL_DHASH_STOP;
|
||||
}
|
||||
|
||||
gkedp->next++;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProperties::GetKeys(uint32_t* aCount, char*** aKeys)
|
||||
{
|
||||
@ -94,28 +72,27 @@ nsProperties::GetKeys(uint32_t* aCount, char*** aKeys)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
uint32_t n = Count();
|
||||
char** k = (char**)moz_xmalloc(n * sizeof(char*));
|
||||
uint32_t count = Count();
|
||||
char** keys = (char**)moz_xmalloc(count * sizeof(char*));
|
||||
uint32_t j = 0;
|
||||
|
||||
GetKeysEnumData gked;
|
||||
gked.keys = k;
|
||||
gked.next = 0;
|
||||
gked.res = NS_OK;
|
||||
for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
|
||||
const char* key = iter.GetKey();
|
||||
keys[j] = strdup(key);
|
||||
|
||||
EnumerateRead(GetKeysEnumerate, &gked);
|
||||
|
||||
nsresult rv = gked.res;
|
||||
if (NS_FAILED(rv)) {
|
||||
// Free 'em all
|
||||
for (uint32_t i = 0; i < gked.next; i++) {
|
||||
free(k[i]);
|
||||
if (!keys[j]) {
|
||||
// Free 'em all
|
||||
for (uint32_t i = 0; i < j; i++) {
|
||||
free(keys[i]);
|
||||
}
|
||||
free(keys);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
free(k);
|
||||
return rv;
|
||||
j++;
|
||||
}
|
||||
|
||||
*aCount = n;
|
||||
*aKeys = k;
|
||||
*aCount = count;
|
||||
*aKeys = keys;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user