Bug 1436655 - Tweak assertions in Add*VarCache() functions. r=glandium
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 23 Mar 2018 15:15:20 +1100
changeset 410064 08af6778dd6a669e896d61ef7599a75d7024d5fd
parent 410063 8509ebf8fbb3af7e580c85aa73d5bb4a9b78c61a
child 410065 16ac5bd4e50c50a62316828b586c5e7a60b28e99
push id101381
push usernnethercote@mozilla.com
push dateTue, 27 Mar 2018 02:34:30 +0000
treeherdermozilla-inbound@16ac5bd4e50c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1436655
milestone61.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 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) {
@@ -4730,20 +4733,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,
@@ -4762,20 +4762,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,
@@ -4792,20 +4789,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;
@@ -4821,20 +4815,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,
@@ -4851,20 +4842,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,
@@ -4883,20 +4871,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,
@@ -4942,20 +4927,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,