Bug 1436655 - Tweak assertions in Add*VarCache() functions. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 23 Mar 2018 15:15:20 +1100
changeset 771489 73be150e8abf58cc8436dc30f3be08a7a6373c45
parent 771488 b4e03ecf060c262d492ce73c7b7c3ff48447c251
child 771490 94997d5f0885ea568f01a264d5811ba9813077c8
push id103687
push usernnethercote@mozilla.com
push dateFri, 23 Mar 2018 04:16:02 +0000
reviewersglandium
bugs1436655
milestone61.0a1
Bug 1436655 - Tweak assertions in Add*VarCache() functions. r=glandium This avoids some repetition. MozReview-Commit-ID: I7aD8JUCCK4
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -2863,33 +2863,36 @@ HaveExistingCacheFor(void* aPtr)
     for (size_t i = 0, count = gCacheData->Length(); i < count; ++i) {
       if ((*gCacheData)[i]->mCacheLocation == aPtr) {
         return true;
       }
     }
   }
   return false;
 }
+#endif
 
 static void
 AssertNotAlreadyCached(const char* aPrefType, const char* aPref, void* aPtr)
 {
+#ifdef DEBUG
+  MOZ_ASSERT(aPtr);
   if (HaveExistingCacheFor(aPtr)) {
     fprintf_stderr(
       stderr,
       "Attempt to add a %s pref cache for preference '%s' at address '%p'"
       "was made. However, a pref was already cached at this address.\n",
       aPrefType,
       aPref,
       aPtr);
     MOZ_ASSERT(false,
                "Should not have an existing pref cache for this address");
   }
+#endif
 }
-#endif
 
 // Although this is a member of Preferences, it measures sPreferences and
 // several other global structures.
 /* static */ void
 Preferences::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                     PrefsSizes& aSizes)
 {
   if (!sPreferences) {
@@ -4732,20 +4735,17 @@ BoolVarChanged(const char* aPref, void* 
   CacheData* cache = static_cast<CacheData*>(aClosure);
   *static_cast<bool*>(cache->mCacheLocation) =
     Preferences::GetBool(aPref, cache->mDefaultValueBool);
 }
 
 /* static */ nsresult
 Preferences::AddBoolVarCache(bool* aCache, const char* aPref, bool aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("bool", aPref, aCache);
-#endif
   *aCache = GetBool(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueBool = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(BoolVarChanged,
                                 aPref,
                                 data,
@@ -4764,20 +4764,17 @@ AtomicBoolVarChanged(const char* aPref, 
 }
 
 template<MemoryOrdering Order>
 /* static */ nsresult
 Preferences::AddAtomicBoolVarCache(Atomic<bool, Order>* aCache,
                                    const char* aPref,
                                    bool aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("bool", aPref, aCache);
-#endif
   *aCache = Preferences::GetBool(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueBool = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(AtomicBoolVarChanged<Order>,
                                 aPref,
                                 data,
@@ -4794,20 +4791,17 @@ IntVarChanged(const char* aPref, void* a
     Preferences::GetInt(aPref, cache->mDefaultValueInt);
 }
 
 /* static */ nsresult
 Preferences::AddIntVarCache(int32_t* aCache,
                             const char* aPref,
                             int32_t aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("int", aPref, aCache);
-#endif
   *aCache = Preferences::GetInt(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueInt = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(
     IntVarChanged, aPref, data, Preferences::ExactMatch, /* isPriority */ true);
   return NS_OK;
@@ -4823,20 +4817,17 @@ AtomicIntVarChanged(const char* aPref, v
 }
 
 template<MemoryOrdering Order>
 /* static */ nsresult
 Preferences::AddAtomicIntVarCache(Atomic<int32_t, Order>* aCache,
                                   const char* aPref,
                                   int32_t aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("int", aPref, aCache);
-#endif
   *aCache = Preferences::GetInt(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueUint = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(AtomicIntVarChanged<Order>,
                                 aPref,
                                 data,
@@ -4853,20 +4844,17 @@ UintVarChanged(const char* aPref, void* 
     Preferences::GetUint(aPref, cache->mDefaultValueUint);
 }
 
 /* static */ nsresult
 Preferences::AddUintVarCache(uint32_t* aCache,
                              const char* aPref,
                              uint32_t aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("uint", aPref, aCache);
-#endif
   *aCache = Preferences::GetUint(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueUint = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(UintVarChanged,
                                 aPref,
                                 data,
@@ -4885,20 +4873,17 @@ AtomicUintVarChanged(const char* aPref, 
 }
 
 template<MemoryOrdering Order>
 /* static */ nsresult
 Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
                                    const char* aPref,
                                    uint32_t aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("uint", aPref, aCache);
-#endif
   *aCache = Preferences::GetUint(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueUint = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(AtomicUintVarChanged<Order>,
                                 aPref,
                                 data,
@@ -4944,20 +4929,17 @@ FloatVarChanged(const char* aPref, void*
   CacheData* cache = static_cast<CacheData*>(aClosure);
   *static_cast<float*>(cache->mCacheLocation) =
     Preferences::GetFloat(aPref, cache->mDefaultValueFloat);
 }
 
 /* static */ nsresult
 Preferences::AddFloatVarCache(float* aCache, const char* aPref, float aDefault)
 {
-  MOZ_ASSERT(aCache);
-#ifdef DEBUG
   AssertNotAlreadyCached("float", aPref, aCache);
-#endif
   *aCache = Preferences::GetFloat(aPref, aDefault);
   CacheData* data = new CacheData();
   data->mCacheLocation = aCache;
   data->mDefaultValueFloat = aDefault;
   CacheDataAppendElement(data);
   Preferences::RegisterCallback(FloatVarChanged,
                                 aPref,
                                 data,