Bug 726002 - Clear some big nsTArrays as early as possible in updates. r=dcamp

This commit is contained in:
Gian-Carlo Pascutto 2012-08-15 09:05:18 +02:00
parent d705e725b0
commit 952775e4c5
4 changed files with 16 additions and 12 deletions

View File

@ -531,6 +531,7 @@ Classifier::ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
NS_ENSURE_SUCCESS(rv, rv);
rv = store->AugmentAdds(AddPrefixHashes);
NS_ENSURE_SUCCESS(rv, rv);
AddPrefixHashes.Clear();
uint32 applied = 0;
bool updateFreshness = false;

View File

@ -120,10 +120,10 @@ public:
ChunkSet& AddChunks() { return mAddChunks; }
ChunkSet& SubChunks() { return mSubChunks; }
const AddPrefixArray& AddPrefixes() const { return mAddPrefixes; }
const AddCompleteArray& AddCompletes() const { return mAddCompletes; }
const SubPrefixArray& SubPrefixes() const { return mSubPrefixes; }
const SubCompleteArray& SubCompletes() const { return mSubCompletes; }
AddPrefixArray& AddPrefixes() { return mAddPrefixes; }
AddCompleteArray& AddCompletes() { return mAddCompletes; }
SubPrefixArray& SubPrefixes() { return mSubPrefixes; }
SubCompleteArray& SubCompletes() { return mSubCompletes; }
// =======
// Updates

View File

@ -171,8 +171,8 @@ LookupCache::Reset()
nsresult
LookupCache::Build(const AddPrefixArray& aAddPrefixes,
const AddCompleteArray& aAddCompletes)
LookupCache::Build(AddPrefixArray& aAddPrefixes,
AddCompleteArray& aAddCompletes)
{
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_COMPLETIONS,
static_cast<PRUint32>(aAddCompletes.Length()));
@ -182,6 +182,7 @@ LookupCache::Build(const AddPrefixArray& aAddPrefixes,
for (uint32 i = 0; i < aAddCompletes.Length(); i++) {
mCompletions.AppendElement(aAddCompletes[i].CompleteHash());
}
aAddCompletes.Clear();
mCompletions.Sort();
Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_PREFIXES,
@ -679,7 +680,7 @@ bool LookupCache::IsPrimed()
}
nsresult
LookupCache::ConstructPrefixSet(const AddPrefixArray& aAddPrefixes)
LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
{
Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_PS_CONSTRUCT_TIME> timer;
@ -693,8 +694,8 @@ LookupCache::ConstructPrefixSet(const AddPrefixArray& aAddPrefixes)
for (uint32 i = 0; i < aAddPrefixes.Length(); i++) {
array.AppendElement(aAddPrefixes[i].PrefixHash().ToUint32());
}
aAddPrefixes.Clear();
// clear old tree
if (array.IsEmpty()) {
// DB is empty, but put a sentinel to show that we looked
array.AppendElement(0);

View File

@ -137,8 +137,9 @@ public:
nsresult Init();
nsresult Open();
nsresult Build(const AddPrefixArray& aAddPrefixes,
const AddCompleteArray& aAddCompletes);
// This will Clear() the passed arrays when done.
nsresult Build(AddPrefixArray& aAddPrefixes,
AddCompleteArray& aAddCompletes);
nsresult GetPrefixes(nsTArray<PRUint32>* aAddPrefixes);
#if DEBUG && defined(PR_LOGGING)
@ -160,9 +161,10 @@ private:
nsresult ReadHeader();
nsresult EnsureSizeConsistent();
nsresult ReadCompletions();
// Construct a Prefix Set with known prefixes
nsresult LoadPrefixSet();
nsresult ConstructPrefixSet(const AddPrefixArray& aAddPrefixes);
// Construct a Prefix Set with known prefixes.
// This will Clear() aAddPrefixes when done.
nsresult ConstructPrefixSet(AddPrefixArray& aAddPrefixes);
struct Header {
uint32 magic;