Browse Source

mNumFreeObjects is only used for an assert, removing it when assertions are off

Jorrit Rouwe 3 years ago
parent
commit
655e5618d5
2 changed files with 7 additions and 5 deletions
  1. 2 0
      Jolt/Core/FixedSizeFreeList.h
  2. 5 5
      Jolt/Core/FixedSizeFreeList.inl

+ 2 - 0
Jolt/Core/FixedSizeFreeList.h

@@ -39,7 +39,9 @@ private:
 	ObjectStorage &			GetStorage(uint32 inObjectIndex)		{ return mPages[inObjectIndex / mPageSize][inObjectIndex % mPageSize]; }
 
 	/// Number of objects that we currently have in the free list / new pages
+#ifdef JPH_ENABLE_ASSERTS
 	atomic<uint32>			mNumFreeObjects;
+#endif // JPH_ENABLE_ASSERTS
 
 	/// Simple counter that makes the first free object pointer update with every CAS so that we don't suffer from the ABA problem
 	atomic<uint32>			mAllocationTag;

+ 5 - 5
Jolt/Core/FixedSizeFreeList.inl

@@ -24,8 +24,8 @@ void FixedSizeFreeList<Object>::Init(uint inMaxObjects, uint inPageSize)
 
 	// Store configuration parameters
 	mNumPages = (inMaxObjects + inPageSize - 1) / inPageSize;
-	mNumFreeObjects = mNumPages * inPageSize;
 	mPageSize = inPageSize;
+	JPH_IF_ENABLE_ASSERTS(mNumFreeObjects = mNumPages * inPageSize;)
 
 	// Allocate page table
 	mPages = new ObjectStorage * [mNumPages];
@@ -69,7 +69,7 @@ uint32 FixedSizeFreeList<Object>::ConstructObject(Parameters &&... inParameters)
 			}
 
 			// Allocation successful
-			--mNumFreeObjects;
+			JPH_IF_ENABLE_ASSERTS(--mNumFreeObjects;)
 			ObjectStorage &storage = GetStorage(first_free);
 			new (&storage.mData) Object(forward<Parameters>(inParameters)...);
 			storage.mNextFreeObject = first_free;
@@ -87,7 +87,7 @@ uint32 FixedSizeFreeList<Object>::ConstructObject(Parameters &&... inParameters)
 			if (mFirstFreeObjectAndTag.compare_exchange_strong(first_free_object_and_tag, new_first_free_object_and_tag))
 			{
 				// Allocation successful
-				--mNumFreeObjects;
+				JPH_IF_ENABLE_ASSERTS(--mNumFreeObjects;)
 				ObjectStorage &storage = GetStorage(first_free);
 				new (&storage.mData) Object(forward<Parameters>(inParameters)...);
 				storage.mNextFreeObject = first_free;
@@ -147,7 +147,7 @@ void FixedSizeFreeList<Object>::DestructObjectBatch(Batch &ioBatch)
 			if (mFirstFreeObjectAndTag.compare_exchange_strong(first_free_object_and_tag, new_first_free_object_and_tag))
 			{
 				// Free successful
-				mNumFreeObjects += ioBatch.mNumObjects;
+				JPH_IF_ENABLE_ASSERTS(mNumFreeObjects += ioBatch.mNumObjects;)
 
 				// Mark the batch as freed
 #ifdef JPH_ENABLE_ASSERTS
@@ -185,7 +185,7 @@ void FixedSizeFreeList<Object>::DestructObject(uint32 inObjectIndex)
 		if (mFirstFreeObjectAndTag.compare_exchange_strong(first_free_object_and_tag, new_first_free_object_and_tag))
 		{
 			// Free successful
-			mNumFreeObjects++;
+			JPH_IF_ENABLE_ASSERTS(mNumFreeObjects++;)
 			return;
 		}
 	}