Bug 1102687 - Avoid copying and allocating 3 times in GetPrefixes. r=dmajor

This commit is contained in:
Gian-Carlo Pascutto
2014-11-24 08:38:29 +01:00
parent 6fbcffc8bb
commit fe253223fe
5 changed files with 40 additions and 32 deletions

View File

@@ -684,24 +684,14 @@ LookupCache::LoadPrefixSet()
}
nsresult
LookupCache::GetPrefixes(nsTArray<uint32_t>* aAddPrefixes)
LookupCache::GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes)
{
if (!mPrimed) {
// This can happen if its a new table, so no error.
LOG(("GetPrefixes from empty LookupCache"));
return NS_OK;
}
uint32_t cnt;
uint32_t *arr;
nsresult rv = mPrefixSet->GetPrefixes(&cnt, &arr);
NS_ENSURE_SUCCESS(rv, rv);
bool appendOk = aAddPrefixes->AppendElements(arr, cnt);
nsMemory::Free(arr);
if (appendOk) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
return mPrefixSet->GetPrefixesNative(aAddPrefixes);
}