Browse Source

Removed a branch from HashTable::SetControlValue (#1360)

Jorrit Rouwe 8 months ago
parent
commit
7e83db65aa
1 changed files with 8 additions and 3 deletions
  1. 8 3
      Jolt/Core/HashTable.h

+ 8 - 3
Jolt/Core/HashTable.h

@@ -124,9 +124,14 @@ private:
 		JPH_ASSERT(inIndex < mMaxSize);
 		mControl[inIndex] = inValue;
 
-		// Mirror the first 15 bytes at the end of the control values
-		if (inIndex < 15)
-			mControl[mMaxSize + inIndex] = inValue;
+		// Mirror the first 15 bytes to the 15 bytes beyond mMaxSize
+		// Note that this is equivalent to:
+		// if (inIndex < 15)
+		//   mControl[inIndex + mMaxSize] = inValue
+		// else
+		//   mControl[inIndex] = inValue
+		// Which performs a needless write if inIndex >= 15 but at least it is branch-less
+		mControl[((inIndex - 15) & (mMaxSize - 1)) + 15] = inValue;
 	}
 
 	/// Get the index and control value for a particular key