From 5a2649faf741f9f168a753586975f8d314676a57 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Mon, 21 May 2018 15:11:01 -0700 Subject: [PATCH] Bug 1434206 - Make LookupCache objects const as much as possible. r=gcp MozReview-Commit-ID: AqC6NUh6ifm --HG-- extra : rebase_source : a125989490e7988021215f47d17d3cb3b0303651 --- toolkit/components/url-classifier/Classifier.cpp | 6 +++--- toolkit/components/url-classifier/LookupCache.cpp | 6 +++--- toolkit/components/url-classifier/LookupCache.h | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index 85d2244a5ef3..dd53da87b5f4 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -873,7 +873,7 @@ void Classifier::GetCacheInfo(const nsACString& aTable, nsIUrlClassifierCacheInfo** aCache) { - RefPtr lookupCache = GetLookupCache(aTable); + RefPtr lookupCache = GetLookupCache(aTable); if (!lookupCache) { return; } @@ -898,7 +898,7 @@ Classifier::RegenActiveTables() for (uint32_t i = 0; i < foundTables.Length(); i++) { nsCString table(foundTables[i]); - RefPtr lookupCache = GetLookupCache(table); + RefPtr lookupCache = GetLookupCache(table); if (!lookupCache) { LOG(("Inactive table (no cache): %s", table.get())); continue; @@ -909,7 +909,7 @@ Classifier::RegenActiveTables() continue; } - if (LookupCache::Cast(lookupCache)) { + if (LookupCache::Cast(lookupCache)) { LOG(("Active v4 table: %s", table.get())); } else { HashStore store(table, GetProvider(table), mRootStoreDirectory); diff --git a/toolkit/components/url-classifier/LookupCache.cpp b/toolkit/components/url-classifier/LookupCache.cpp index 2782f1464cf5..89accaa4db97 100644 --- a/toolkit/components/url-classifier/LookupCache.cpp +++ b/toolkit/components/url-classifier/LookupCache.cpp @@ -243,7 +243,7 @@ LookupCache::ClearAll() } void -LookupCache::GetCacheInfo(nsIUrlClassifierCacheInfo** aCache) +LookupCache::GetCacheInfo(nsIUrlClassifierCacheInfo** aCache) const { MOZ_ASSERT(aCache); @@ -508,7 +508,7 @@ nsCString GetFormattedTimeString(int64_t aCurTimeSec) } void -LookupCache::DumpCache() +LookupCache::DumpCache() const { if (!LOG_ENABLED()) { return; @@ -778,7 +778,7 @@ LookupCacheV2::ConstructPrefixSet(AddPrefixArray& aAddPrefixes) #if defined(DEBUG) void -LookupCacheV2::DumpCompletions() +LookupCacheV2::DumpCompletions() const { if (!LOG_ENABLED()) return; diff --git a/toolkit/components/url-classifier/LookupCache.h b/toolkit/components/url-classifier/LookupCache.h index 6cc14a7978a4..f4f5457e25ba 100644 --- a/toolkit/components/url-classifier/LookupCache.h +++ b/toolkit/components/url-classifier/LookupCache.h @@ -212,10 +212,10 @@ public: bool IsInCache(uint32_t key) const { return mFullHashCache.Get(key); }; #if DEBUG - void DumpCache(); + void DumpCache() const; #endif - void GetCacheInfo(nsIUrlClassifierCacheInfo** aCache); + void GetCacheInfo(nsIUrlClassifierCacheInfo** aCache) const; virtual nsresult Open(); virtual nsresult Init() = 0; @@ -233,6 +233,10 @@ public: static T* Cast(LookupCache* aThat) { return ((aThat && T::VER == aThat->Ver()) ? reinterpret_cast(aThat) : nullptr); } + template + static const T* Cast(const LookupCache* aThat) { + return ((aThat && T::VER == aThat->Ver()) ? reinterpret_cast(aThat) : nullptr); + } private: nsresult LoadPrefixSet(); @@ -297,7 +301,7 @@ public: int64_t aExpirySec = 0); #if DEBUG - void DumpCompletions(); + void DumpCompletions() const; #endif static const int VER;