Bug 1434206 - Replace a pointer with a reference. r?gcp draft
authorFrancois Marier <francois@mozilla.com>
Tue, 15 May 2018 17:18:18 -0700
changeset 467868 976e25b49758
parent 467867 0d7a4e1c0079
child 467869 a1a382f2e773
push id180
push userfmarier@mozilla.com
push date2018-05-29 01:16 +0000
reviewersgcp
bugs1434206
milestone62.0a1
Bug 1434206 - Replace a pointer with a reference. r?gcp This will prevent our holding on to this pointer incorrectly in the future. MozReview-Commit-ID: H8ueIOK1qAK
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/Classifier.h
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/tests/gtest/TestClassifier.cpp
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -1466,17 +1466,17 @@ Classifier::GetLookupCache(const nsACStr
   }
   return nullptr;
 }
 
 nsresult
 Classifier::ReadNoiseEntries(const Prefix& aPrefix,
                              const nsACString& aTableName,
                              uint32_t aCount,
-                             PrefixArray* aNoiseEntries)
+                             PrefixArray& aNoiseEntries)
 {
   FallibleTArray<uint32_t> prefixes;
   nsresult rv;
 
   LookupCache *cache = GetLookupCache(aTableName);
   if (!cache) {
     return NS_ERROR_FAILURE;
   }
@@ -1519,17 +1519,17 @@ Classifier::ReadNoiseEntries(const Prefi
     // int, should revert endian to make sure we will send hex string correctly
     // See https://bugzilla.mozilla.org/show_bug.cgi?id=1283007#c23
     if (!cacheV2 && !bool(MOZ_BIG_ENDIAN)) {
       hash = NativeEndian::swapFromBigEndian(prefixes[idx]);
     }
 
     newPrefix.FromUint32(hash);
     if (newPrefix != aPrefix) {
-      aNoiseEntries->AppendElement(newPrefix);
+      aNoiseEntries.AppendElement(newPrefix);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 Classifier::LoadMetadata(nsIFile* aDirectory, nsACString& aResult)
--- a/toolkit/components/url-classifier/Classifier.h
+++ b/toolkit/components/url-classifier/Classifier.h
@@ -84,17 +84,17 @@ public:
 
   /*
    * Get a bunch of extra prefixes to query for completion
    * and mask the real entry being requested
    */
   nsresult ReadNoiseEntries(const Prefix& aPrefix,
                             const nsACString& aTableName,
                             uint32_t aCount,
-                            PrefixArray* aNoiseEntries);
+                            PrefixArray& aNoiseEntries);
 
 #ifdef MOZ_SAFEBROWSING_DUMP_FAILED_UPDATES
   nsresult DumpRawTableUpdates(const nsACString& aRawUpdates);
 #endif
 
   static void SplitTables(const nsACString& str, nsTArray<nsCString>& tables);
 
   // Given a root store directory, return a private store directory
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -317,17 +317,17 @@ nsUrlClassifierDBServiceWorker::AddNoise
   }
 
   if (aCount < 1) {
     return NS_OK;
   }
 
   PrefixArray noiseEntries;
   nsresult rv = mClassifier->ReadNoiseEntries(aPrefix, tableName,
-                                              aCount, &noiseEntries);
+                                              aCount, noiseEntries);
   NS_ENSURE_SUCCESS(rv, rv);
 
   for (uint32_t i = 0; i < noiseEntries.Length(); i++) {
     LookupResult *result = results.AppendElement(fallible);
     if (!result) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
--- a/toolkit/components/url-classifier/tests/gtest/TestClassifier.cpp
+++ b/toolkit/components/url-classifier/tests/gtest/TestClassifier.cpp
@@ -75,17 +75,17 @@ TestReadNoiseEntries(Classifier* classif
   LookupResult result;
   result.hash.complete = lookupHash;
 
   PrefixArray noiseEntries;
   uint32_t noiseCount = 3;
   nsresult rv;
   rv = classifier->ReadNoiseEntries(result.hash.fixedLengthPrefix,
                                     aTable, noiseCount,
-                                    &noiseEntries);
+                                    noiseEntries);
   ASSERT_TRUE(rv == NS_OK);
   EXPECT_TRUE(noiseEntries.Length() > 0);
 
   for (uint32_t i = 0; i < noiseEntries.Length(); i++) {
     // Test the noise entry should not equal the "real" hash request
     EXPECT_NE(noiseEntries[i], result.hash.fixedLengthPrefix);
     // Test the noise entry should exist in the cached prefix array
     nsAutoCString partialHash;