Backout 35bf0d62cc30 (Bug 726002). rs=dcamp a=akeybl
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 01 May 2012 12:12:34 +0200
changeset 92151 cfd1455c63305775182adf8e97d183efdcbe962d
parent 92150 8c4ce03cc1083642b060f6ddd1e616ea32c7f627
child 92152 c70e9dd2057b41dac13bfbedd8313ec69175eddd
push idunknown
push userunknown
push dateunknown
reviewersdcamp, akeybl
bugs726002
milestone13.0
backs out35bf0d62cc305d4caf00aeb448cb93a915462a83
Backout 35bf0d62cc30 (Bug 726002). rs=dcamp a=akeybl
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/HashStore.h
toolkit/components/url-classifier/LookupCache.cpp
toolkit/components/url-classifier/LookupCache.h
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -526,17 +526,16 @@ Classifier::ApplyTableUpdates(nsTArray<T
   if (!prefixSet) {
     return NS_ERROR_FAILURE;
   }
   nsTArray<PRUint32> AddPrefixHashes;
   rv = prefixSet->GetPrefixes(&AddPrefixHashes);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = store->AugmentAdds(AddPrefixHashes);
   NS_ENSURE_SUCCESS(rv, rv);
-  AddPrefixHashes.Clear();
 
   uint32 applied = 0;
   bool updateFreshness = false;
 
   for (uint32 i = 0; i < aUpdates->Length(); i++) {
     TableUpdate *update = aUpdates->ElementAt(i);
     if (!update || !update->TableName().Equals(store->TableName()))
       continue;
--- a/toolkit/components/url-classifier/HashStore.h
+++ b/toolkit/components/url-classifier/HashStore.h
@@ -115,20 +115,20 @@ public:
 
   const nsCString& TableName() const { return mTableName; };
 
   nsresult Open();
   nsresult AugmentAdds(const nsTArray<PRUint32>& aPrefixes);
 
   ChunkSet& AddChunks() { return mAddChunks; }
   ChunkSet& SubChunks() { return mSubChunks; }
-  AddPrefixArray& AddPrefixes() { return mAddPrefixes; }
-  AddCompleteArray& AddCompletes() { return mAddCompletes; }
-  SubPrefixArray& SubPrefixes() { return mSubPrefixes; }
-  SubCompleteArray& SubCompletes() { return mSubCompletes; }
+  const AddPrefixArray& AddPrefixes() const { return mAddPrefixes; }
+  const AddCompleteArray& AddCompletes() const { return mAddCompletes; }
+  const SubPrefixArray& SubPrefixes() const { return mSubPrefixes; }
+  const SubCompleteArray& SubCompletes() const { return mSubCompletes; }
 
   // =======
   // Updates
   // =======
   // Begin the update process.  Reads the store into memory.
   nsresult BeginUpdate();
 
   // Imports the data from a TableUpdate.
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -166,28 +166,27 @@ LookupCache::Reset()
 
   Clear();
 
   return NS_OK;
 }
 
 
 nsresult
-LookupCache::Build(AddPrefixArray& aAddPrefixes,
-                   AddCompleteArray& aAddCompletes)
+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++) {
     mCompletions.AppendElement(aAddCompletes[i].CompleteHash());
   }
-  aAddCompletes.Clear();
   mCompletions.Sort();
 
   Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_PREFIXES,
                         static_cast<PRUint32>(aAddPrefixes.Length()));
 
   nsresult rv = ConstructPrefixSet(aAddPrefixes);
   NS_ENSURE_SUCCESS(rv, rv);
   mPrimed = true;
@@ -675,32 +674,32 @@ LookupCache::GetHostKeys(const nsACStrin
 }
 
 bool LookupCache::IsPrimed()
 {
   return mPrimed;
 }
 
 nsresult
-LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
+LookupCache::ConstructPrefixSet(const 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;
   }
 
   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);
   }
   // PrefixSet requires sorted order
   array.Sort();
 
   // construct new one, replace old entries
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -132,19 +132,18 @@ public:
 
   LookupCache(const nsACString& aTableName, nsIFile* aStoreFile);
   ~LookupCache();
 
   const nsCString &TableName() const { return mTableName; }
 
   nsresult Init();
   nsresult Open();
-  // This will Clear() the passed arrays when done.
-  nsresult Build(AddPrefixArray& aAddPrefixes,
-                 AddCompleteArray& aAddCompletes);
+  nsresult Build(const AddPrefixArray& aAddPrefixes,
+                 const AddCompleteArray& aAddCompletes);
   nsresult GetPrefixes(nsTArray<PRUint32>* aAddPrefixes);
 
 #if DEBUG && defined(PR_LOGGING)
   void Dump();
 #endif
   nsresult WriteFile();
   nsresult Has(const Completion& aCompletion,
                const Completion& aHostkey,
@@ -156,20 +155,19 @@ public:
 private:
 
   void Clear();
   nsresult Reset();
   void UpdateHeader();
   nsresult ReadHeader();
   nsresult EnsureSizeConsistent();
   nsresult ReadCompletions();
+  // Construct a Prefix Set with known prefixes
   nsresult LoadPrefixSet();
-  // Construct a Prefix Set with known prefixes.
-  // This will Clear() aAddPrefixes when done.
-  nsresult ConstructPrefixSet(AddPrefixArray& aAddPrefixes);
+  nsresult ConstructPrefixSet(const AddPrefixArray& aAddPrefixes);
 
   struct Header {
     uint32 magic;
     uint32 version;
     uint32 numCompletions;
   };
   Header mHeader;