Bug 726002 - More OOM handling in UrlClassifier. r=dcamp

This commit is contained in:
Gian-Carlo Pascutto 2012-02-13 13:17:31 +01:00
Родитель c7670cd9c8
Коммит 8408f11532
1 изменённых файлов: 11 добавлений и 8 удалений

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

@ -174,6 +174,9 @@ nsresult
LookupCache::Build(const AddPrefixArray& aAddPrefixes,
const AddCompleteArray& aAddCompletes)
{
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_COMPLETIONS,
static_cast<PRUint32>(aAddCompletes.Length()));
mCompletions.Clear();
mCompletions.SetCapacity(aAddCompletes.Length());
for (uint32 i = 0; i < aAddCompletes.Length(); i++) {
@ -181,16 +184,13 @@ LookupCache::Build(const AddPrefixArray& aAddPrefixes,
}
mCompletions.Sort();
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_COMPLETIONS,
static_cast<PRUint32>(mCompletions.Length()));
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_PREFIXES,
static_cast<PRUint32>(aAddPrefixes.Length()));
nsresult rv = ConstructPrefixSet(aAddPrefixes);
NS_ENSURE_SUCCESS(rv, rv);
mPrimed = true;
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_PREFIXES,
static_cast<PRUint32>(aAddPrefixes.Length()));
return NS_OK;
}
@ -683,8 +683,11 @@ LookupCache::ConstructPrefixSet(const AddPrefixArray& aAddPrefixes)
{
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_PS_CONSTRUCT_TIME> timer;
nsTArray<PRUint32> array;
array.SetCapacity(aAddPrefixes.Length());
FallibleTArray<PRUint32> array;
nsresult rv = array.SetCapacity(aAddPrefixes.Length());
if (NS_FAILED(rv)) {
goto error_bailout;
}
for (uint32 i = 0; i < aAddPrefixes.Length(); i++) {
array.AppendElement(aAddPrefixes[i].PrefixHash().ToUint32());
@ -699,7 +702,7 @@ LookupCache::ConstructPrefixSet(const AddPrefixArray& aAddPrefixes)
array.Sort();
// construct new one, replace old entries
nsresult rv = mPrefixSet->SetPrefixes(array.Elements(), array.Length());
rv = mPrefixSet->SetPrefixes(array.Elements(), array.Length());
if (NS_FAILED(rv)) {
goto error_bailout;
}