From 8856edf4a7ae2dc51cad25519df113b413767dff Mon Sep 17 00:00:00 2001 From: Mahdi Rakhshandehroo <24380301+mrakh@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:24:14 -0700 Subject: [PATCH] Hoist assert in Deque::getItem Compiler warns about `control reaches end of non-void function` due to no return statement in the else block. Directly asserting the condition should accomplish the same thing while suppressing the warning. --- include/reactphysics3d/containers/Deque.h | 34 ++++++++++------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/include/reactphysics3d/containers/Deque.h b/include/reactphysics3d/containers/Deque.h index 8c4f55e2..c0654d09 100644 --- a/include/reactphysics3d/containers/Deque.h +++ b/include/reactphysics3d/containers/Deque.h @@ -91,30 +91,26 @@ class Deque { /// Return a reference to an item at the given virtual index in range [0; mSize-1] T& getItem(uint64 virtualIndex) const { - // If the virtual index is valid - if (virtualIndex < mSize) { + // Ensure the virtual index is valid + assert(virtualIndex < mSize); - uint64 chunkIndex = mFirstChunkIndex; - uint64 itemIndex = mFirstItemIndex; + uint64 chunkIndex = mFirstChunkIndex; + uint64 itemIndex = mFirstItemIndex; - const uint64 nbItemsFirstChunk = CHUNK_NB_ITEMS - mFirstItemIndex; - if (virtualIndex < nbItemsFirstChunk) { - itemIndex += virtualIndex; - } - else { - - virtualIndex -= nbItemsFirstChunk; - chunkIndex++; - - chunkIndex += virtualIndex / CHUNK_NB_ITEMS; - itemIndex = virtualIndex % CHUNK_NB_ITEMS; - } - - return mChunks[chunkIndex][itemIndex]; + const uint64 nbItemsFirstChunk = CHUNK_NB_ITEMS - mFirstItemIndex; + if (virtualIndex < nbItemsFirstChunk) { + itemIndex += virtualIndex; } else { - assert(false); + + virtualIndex -= nbItemsFirstChunk; + chunkIndex++; + + chunkIndex += virtualIndex / CHUNK_NB_ITEMS; + itemIndex = virtualIndex % CHUNK_NB_ITEMS; } + + return mChunks[chunkIndex][itemIndex]; } /// Add more chunks