Backout db52b4916cde (Bug 673470). rs=dcamp a=mfinkle
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Fri, 20 Apr 2012 07:46:46 +0200
changeset 95347 8c00bd3fa27052d97039395244c9428bede75e6c
parent 95346 46e19522aa98e5e551ab747f57ac6e6792155907
child 95348 6923b654d6112e1ae67dd0adf4aad4f1a9515151
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp, mfinkle
bugs673470
milestone14.0a1
backs outdb52b4916cdecff426efdda6896eef271f693d42
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backout db52b4916cde (Bug 673470). rs=dcamp a=mfinkle
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/Classifier.h
toolkit/components/url-classifier/HashStore.cpp
toolkit/components/url-classifier/HashStore.h
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -177,18 +177,16 @@ Classifier::Open(nsIFile& aCacheDirector
     Reset();
     return NS_ERROR_FAILURE;
   }
 
   if (!mTableFreshness.Init()) {
     return NS_ERROR_FAILURE;
   }
 
-  RegenActiveTables();
-
   return NS_OK;
 }
 
 nsresult
 Classifier::Close()
 {
   DropStores();
 
@@ -211,17 +209,16 @@ Classifier::Reset()
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = file->Remove(false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   mTableFreshness.Clear();
-  RegenActiveTables();
 
   return NS_OK;
 }
 
 void
 Classifier::TableRequest(nsACString& aResult)
 {
   nsTArray<nsCString> tables;
@@ -366,17 +363,16 @@ Classifier::ApplyUpdates(nsTArray<TableU
       rv = ApplyTableUpdates(aUpdates, aUpdates->ElementAt(i)->TableName());
       if (NS_FAILED(rv)) {
         Reset();
         return rv;
       }
     }
   }
   aUpdates->Clear();
-  RegenActiveTables();
   LOG(("Done applying updates."));
 
 #if defined(PR_LOGGING)
   if (LOG_ENABLED() || true) {
     PRIntervalTime clockEnd = PR_IntervalNow();
     LOG(("update took %dms\n",
          PR_IntervalToMilliseconds(clockEnd - clockStart)));
   }
@@ -405,51 +401,16 @@ Classifier::DropStores()
   mHashStores.Clear();
   for (uint32 i = 0; i < mLookupCaches.Length(); i++) {
     delete mLookupCaches[i];
   }
   mLookupCaches.Clear();
 }
 
 nsresult
-Classifier::RegenActiveTables()
-{
-  mActiveTablesCache.Clear();
-
-  nsTArray<nsCString> foundTables;
-  ScanStoreDir(foundTables);
-
-  for (uint32 i = 0; i < foundTables.Length(); i++) {
-    nsAutoPtr<HashStore> store(new HashStore(nsCString(foundTables[i]), mStoreDirectory));
-    if (!store)
-      return NS_ERROR_OUT_OF_MEMORY;
-
-    nsresult rv = store->Open();
-    if (NS_FAILED(rv))
-      continue;
-
-    LookupCache *lookupCache = GetLookupCache(store->TableName());
-    if (!lookupCache) {
-      continue;
-    }
-
-    const ChunkSet &adds = store->AddChunks();
-    const ChunkSet &subs = store->SubChunks();
-
-    if (adds.Length() == 0 && subs.Length() == 0)
-      continue;
-
-    LOG(("Active table: %s", store->TableName().get()));
-    mActiveTablesCache.AppendElement(store->TableName());
-  }
-
-  return NS_OK;
-}
-
-nsresult
 Classifier::ScanStoreDir(nsTArray<nsCString>& aTables)
 {
   nsCOMPtr<nsISimpleEnumerator> entries;
   nsresult rv = mStoreDirectory->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore;
   while (NS_SUCCEEDED(rv = entries->HasMoreElements(&hasMore)) && hasMore) {
@@ -472,17 +433,45 @@ Classifier::ScanStoreDir(nsTArray<nsCStr
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 Classifier::ActiveTables(nsTArray<nsCString>& aTables)
 {
-  aTables = mActiveTablesCache;
+  aTables.Clear();
+
+  nsTArray<nsCString> foundTables;
+  ScanStoreDir(foundTables);
+
+  for (uint32 i = 0; i < foundTables.Length(); i++) {
+    nsAutoPtr<HashStore> store(new HashStore(nsCString(foundTables[i]), mStoreDirectory));
+    if (!store)
+      return NS_ERROR_OUT_OF_MEMORY;
+
+    nsresult rv = store->Open();
+    if (NS_FAILED(rv))
+      continue;
+
+    LookupCache *lookupCache = GetLookupCache(store->TableName());
+    if (!lookupCache) {
+      continue;
+    }
+
+    const ChunkSet &adds = store->AddChunks();
+    const ChunkSet &subs = store->SubChunks();
+
+    if (adds.Length() == 0 && subs.Length() == 0)
+      continue;
+
+    LOG(("Active table: %s", store->TableName().get()));
+    aTables.AppendElement(store->TableName());
+  }
+
   return NS_OK;
 }
 
 /*
  * This will consume+delete updates from the passed nsTArray.
 */
 nsresult
 Classifier::ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
--- a/toolkit/components/url-classifier/Classifier.h
+++ b/toolkit/components/url-classifier/Classifier.h
@@ -99,30 +99,28 @@ public:
    * and mask the real entry being requested
    */
   nsresult ReadNoiseEntries(const Prefix& aPrefix,
                             const nsACString& aTableName,
                             PRInt32 aCount,
                             PrefixArray* aNoiseEntries);
 private:
   void DropStores();
-  nsresult RegenActiveTables();
   nsresult ScanStoreDir(nsTArray<nsCString>& aTables);
 
   nsresult ApplyTableUpdates(nsTArray<TableUpdate*>* aUpdates,
                              const nsACString& aTable);
 
   LookupCache *GetLookupCache(const nsACString& aTable);
   nsresult InitKey();
 
   nsCOMPtr<nsICryptoHash> mCryptoHash;
   nsCOMPtr<nsIFile> mStoreDirectory;
   nsTArray<HashStore*> mHashStores;
   nsTArray<LookupCache*> mLookupCaches;
-  nsTArray<nsCString> mActiveTablesCache;
   PRUint32 mHashKey;
   // Stores the last time a given table was updated (seconds).
   nsDataHashtable<nsCStringHashKey, PRInt64> mTableFreshness;
   PRUint32 mFreshTime;
 };
 
 }
 }
--- a/toolkit/components/url-classifier/HashStore.cpp
+++ b/toolkit/components/url-classifier/HashStore.cpp
@@ -212,22 +212,18 @@ HashStore::Open()
   }
 
   if (rv == NS_ERROR_FILE_NOT_FOUND) {
     Clear();
     UpdateHeader();
     return NS_OK;
   }
 
-  PRInt64 fileSize;
-  rv = storeFile->GetFileSize(&fileSize);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   rv = NS_NewBufferedInputStream(getter_AddRefs(mInputStream), origStream,
-                                 fileSize);
+                                 BUFFER_SIZE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = CheckChecksum(storeFile);
   if (NS_FAILED(rv)) {
     Reset();
     return rv;
   }
 
@@ -783,28 +779,24 @@ HashStore::WriteFile()
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISafeOutputStream> safeOut = do_QueryInterface(out, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = safeOut->Finish();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  PRInt64 fileSize;
-  rv = storeFile->GetFileSize(&fileSize);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   // Reopen the file now that we've rewritten it.
   nsCOMPtr<nsIInputStream> origStream;
   rv = NS_NewLocalFileInputStream(getter_AddRefs(origStream), storeFile,
                                   PR_RDONLY);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = NS_NewBufferedInputStream(getter_AddRefs(mInputStream), origStream,
-                                 fileSize);
+                                 BUFFER_SIZE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 HashStore::FinishUpdate()
 {
--- a/toolkit/components/url-classifier/HashStore.h
+++ b/toolkit/components/url-classifier/HashStore.h
@@ -147,16 +147,18 @@ public:
 
   // Drop memory used during the update process.
   nsresult FinishUpdate();
 
   // Force the entire store in memory
   nsresult ReadEntireStore();
 
 private:
+  static const int BUFFER_SIZE = 6 * 1024 * 1024;
+
   void Clear();
   nsresult Reset();
 
   nsresult ReadHeader();
   nsresult SanityCheck(nsIFile* aStoreFile);
   nsresult CalculateChecksum(nsCAutoString& aChecksum, bool aChecksumPresent);
   nsresult CheckChecksum(nsIFile* aStoreFile);
   void UpdateHeader();