Bug 1050108 - Remove superfluous member variables in PrefixSet. r=mmc
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 14 Oct 2014 13:16:11 +0200
changeset 210282 1f089acdfd64d596cea894d9967589d6430bd1a9
parent 210281 b17fa4f3eae4b9488ce4e8e06b7a995db93d7d76
child 210283 bc87d0ccf6a9cf51056fd889576f83335887915c
push id50395
push usergpascutto@mozilla.com
push dateTue, 14 Oct 2014 11:16:42 +0000
treeherdermozilla-inbound@1f089acdfd64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmc
bugs1050108
milestone36.0a1
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
Bug 1050108 - Remove superfluous member variables in PrefixSet. r=mmc
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -36,18 +36,17 @@ static const PRLogModuleInfo *gUrlClassi
 #endif
 
 NS_IMPL_ISUPPORTS(
   nsUrlClassifierPrefixSet, nsIUrlClassifierPrefixSet, nsIMemoryReporter)
 
 MOZ_DEFINE_MALLOC_SIZE_OF(UrlClassifierMallocSizeOf)
 
 nsUrlClassifierPrefixSet::nsUrlClassifierPrefixSet()
-  : mHasPrefixes(false)
-  , mTotalPrefixes(0)
+  : mTotalPrefixes(0)
   , mMemoryInUse(0)
   , mMemoryReportPath()
 {
 #if defined(PR_LOGGING)
   if (!gUrlClassifierPrefixSetLog)
     gUrlClassifierPrefixSetLog = PR_NewLogModule("UrlClassifierPrefixSet");
 #endif
 }
@@ -72,22 +71,21 @@ nsUrlClassifierPrefixSet::~nsUrlClassifi
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::SetPrefixes(const uint32_t* aArray, uint32_t aLength)
 {
   nsresult rv = NS_OK;
 
   if (aLength <= 0) {
-    if (mHasPrefixes) {
+    if (mIndexPrefixes.Length() > 0) {
       LOG(("Clearing PrefixSet"));
       mIndexDeltas.Clear();
       mIndexPrefixes.Clear();
       mTotalPrefixes = 0;
-      mHasPrefixes = false;
     }
   } else {
     rv = MakePrefixSet(aArray, aLength);
   }
 
   mMemoryInUse = SizeOfIncludingThis(UrlClassifierMallocSizeOf);
 
   return rv;
@@ -134,18 +132,16 @@ nsUrlClassifierPrefixSet::MakePrefixSet(
 
   mIndexPrefixes.Compact();
   mIndexDeltas.Compact();
 
   LOG(("Total number of indices: %d", aLength));
   LOG(("Total number of deltas: %d", totalDeltas));
   LOG(("Total number of delta chunks: %d", mIndexDeltas.Length()));
 
-  mHasPrefixes = true;
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::GetPrefixes(uint32_t* aCount,
                                       uint32_t** aPrefixes)
 {
   NS_ENSURE_ARG_POINTER(aCount);
@@ -196,17 +192,17 @@ uint32_t nsUrlClassifierPrefixSet::BinSe
   return end;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::Contains(uint32_t aPrefix, bool* aFound)
 {
   *aFound = false;
 
-  if (!mHasPrefixes) {
+  if (mIndexPrefixes.Length() == 0) {
     return NS_OK;
   }
 
   uint32_t target = aPrefix;
 
   // We want to do a "Price is Right" binary search, that is, we want to find
   // the index of the value either equal to the target or the closest value
   // that is less than the target.
@@ -265,17 +261,17 @@ nsUrlClassifierPrefixSet::SizeOfIncludin
   }
   n += mIndexPrefixes.SizeOfExcludingThis(aMallocSizeOf);
   return n;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::IsEmpty(bool * aEmpty)
 {
-  *aEmpty = !mHasPrefixes;
+  *aEmpty = (mIndexPrefixes.Length() == 0);
   return NS_OK;
 }
 
 nsresult
 nsUrlClassifierPrefixSet::LoadFromFd(AutoFDClose& fileFd)
 {
   uint32_t magic;
   int32_t read;
@@ -323,18 +319,16 @@ nsUrlClassifierPrefixSet::LoadFromFd(Aut
       if (numInDelta > 0) {
         mIndexDeltas[i].SetLength(numInDelta);
         mTotalPrefixes += numInDelta;
         toRead = numInDelta * sizeof(uint16_t);
         read = PR_Read(fileFd, mIndexDeltas[i].Elements(), toRead);
         NS_ENSURE_TRUE(read == toRead, NS_ERROR_FILE_CORRUPTED);
       }
     }
-
-    mHasPrefixes = true;
   } else {
     LOG(("Version magic mismatch, not loading"));
     return NS_ERROR_FILE_CORRUPTED;
   }
 
   MOZ_ASSERT(mIndexPrefixes.Length() == mIndexDeltas.Length());
   LOG(("Loading PrefixSet successful"));
 
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
@@ -51,19 +51,16 @@ protected:
   nsresult MakePrefixSet(const uint32_t* aArray, uint32_t aLength);
   uint32_t BinSearch(uint32_t start, uint32_t end, uint32_t target);
   nsresult LoadFromFd(mozilla::AutoFDClose& fileFd);
   nsresult StoreToFd(mozilla::AutoFDClose& fileFd);
 
   // Return the estimated size of the set on disk and in memory, in bytes.
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
 
-  // boolean indicating whether |setPrefixes| has been
-  // called with a non-empty array.
-  bool mHasPrefixes;
   // list of fully stored prefixes, that also form the
   // start of a run of deltas in mIndexDeltas.
   nsTArray<uint32_t> mIndexPrefixes;
   // array containing arrays of deltas from indices.
   // Index to the place that matches the closest lower
   // prefix from mIndexPrefix. Then every "delta" corresponds
   // to a prefix in the PrefixSet.
   nsTArray<nsTArray<uint16_t> > mIndexDeltas;