Bug 673470 - Make the PrefixSet/LookupCache construction infallible again. r=dcamp f=jlebar

This commit is contained in:
Gian-Carlo Pascutto 2012-08-15 09:09:25 +02:00
parent a4e635e69a
commit 32e2eaa965
3 changed files with 13 additions and 29 deletions

View File

@ -355,7 +355,7 @@ HISTOGRAM(URLCLASSIFIER_PS_FALLOCATE_TIME, 1, 1000, 10, EXPONENTIAL, "Time spent
HISTOGRAM(URLCLASSIFIER_PS_CONSTRUCT_TIME, 1, 5000, 15, EXPONENTIAL, "Time spent constructing PrefixSet from DB (ms)")
HISTOGRAM(URLCLASSIFIER_LC_PREFIXES, 1, 1500000, 15, LINEAR, "Size of the prefix cache in entries")
HISTOGRAM(URLCLASSIFIER_LC_COMPLETIONS, 1, 200, 10, EXPONENTIAL, "Size of the completion cache in entries")
HISTOGRAM_BOOLEAN(URLCLASSIFIER_PS_OOM, "Did UrlClassifier run out of memory during PrefixSet construction?")
HISTOGRAM_BOOLEAN(URLCLASSIFIER_PS_FAILURE, "Did UrlClassifier fail to construct the PrefixSet?")
#endif
/**

View File

@ -713,12 +713,8 @@ LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
{
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_PS_CONSTRUCT_TIME> timer;
FallibleTArray<PRUint32> array;
nsresult rv;
if (!array.SetCapacity(aAddPrefixes.Length())) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto error_bailout;
}
nsTArray<PRUint32> array;
array.SetCapacity(aAddPrefixes.Length());
for (uint32 i = 0; i < aAddPrefixes.Length(); i++) {
array.AppendElement(aAddPrefixes[i].PrefixHash().ToUint32());
@ -735,7 +731,7 @@ LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
#endif
// construct new one, replace old entries
rv = mPrefixSet->SetPrefixes(array.Elements(), array.Length());
nsresult rv = mPrefixSet->SetPrefixes(array.Elements(), array.Length());
if (NS_FAILED(rv)) {
goto error_bailout;
}
@ -756,9 +752,7 @@ LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
sentinel.Clear();
sentinel.AppendElement(0);
mPrefixSet->SetPrefixes(sentinel.Elements(), sentinel.Length());
if (rv == NS_ERROR_OUT_OF_MEMORY) {
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_PS_OOM, 1);
}
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_PS_FAILURE, 1);
return rv;
}

View File

@ -165,34 +165,24 @@ nsUrlClassifierPrefixSet::MakePrefixSet(const PRUint32* aPrefixes, PRUint32 aLen
}
#endif
FallibleTArray<PRUint32> newIndexPrefixes;
FallibleTArray<PRUint32> newIndexStarts;
FallibleTArray<PRUint16> newDeltas;
nsTArray<PRUint32> newIndexPrefixes;
nsTArray<PRUint32> newIndexStarts;
nsTArray<PRUint16> newDeltas;
if (!newIndexPrefixes.AppendElement(aPrefixes[0])) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!newIndexStarts.AppendElement(newDeltas.Length())) {
return NS_ERROR_OUT_OF_MEMORY;
}
newIndexPrefixes.AppendElement(aPrefixes[0]);
newIndexStarts.AppendElement(newDeltas.Length());
PRUint32 numOfDeltas = 0;
PRUint32 currentItem = aPrefixes[0];
for (PRUint32 i = 1; i < aLength; i++) {
if ((numOfDeltas >= DELTAS_LIMIT) ||
(aPrefixes[i] - currentItem >= MAX_INDEX_DIFF)) {
if (!newIndexStarts.AppendElement(newDeltas.Length())) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!newIndexPrefixes.AppendElement(aPrefixes[i])) {
return NS_ERROR_OUT_OF_MEMORY;
}
newIndexStarts.AppendElement(newDeltas.Length());
newIndexPrefixes.AppendElement(aPrefixes[i]);
numOfDeltas = 0;
} else {
PRUint16 delta = aPrefixes[i] - currentItem;
if (!newDeltas.AppendElement(delta)) {
return NS_ERROR_OUT_OF_MEMORY;
}
newDeltas.AppendElement(delta);
numOfDeltas++;
}
currentItem = aPrefixes[i];