From 72b178b9fc6825adc1607afdfed4c8cdae10f615 Mon Sep 17 00:00:00 2001 From: AdamCichocki Date: Mon, 23 Jan 2023 14:51:02 +0100 Subject: [PATCH] Optimized usedVertexIndices by using bitmask instead of unordered_set --- code/PostProcessing/JoinVerticesProcess.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/PostProcessing/JoinVerticesProcess.cpp b/code/PostProcessing/JoinVerticesProcess.cpp index 0423ab5c2..30831eed0 100644 --- a/code/PostProcessing/JoinVerticesProcess.cpp +++ b/code/PostProcessing/JoinVerticesProcess.cpp @@ -264,12 +264,13 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) { // We should care only about used vertices, not all of them // (this can happen due to original file vertices buffer being used by // multiple meshes) - std::unordered_set usedVertexIndices; - usedVertexIndices.reserve(pMesh->mNumVertices); - for( unsigned int a = 0; a < pMesh->mNumFaces; a++) { + std::vector usedVertexIndicesMask; + usedVertexIndicesMask.resize((pMesh->mNumVertices + 31) / 32, 0); + for (unsigned int a = 0; a < pMesh->mNumFaces; a++) { aiFace& face = pMesh->mFaces[a]; - for( unsigned int b = 0; b < face.mNumIndices; b++) { - usedVertexIndices.insert(face.mIndices[b]); + for (unsigned int b = 0; b < face.mNumIndices; b++) { + const unsigned int currIndex = face.mIndices[b]; + usedVertexIndicesMask[currIndex / 32] |= 1u << (currIndex % 32); } } @@ -335,7 +336,7 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) { int newIndex = 0; for( unsigned int a = 0; a < pMesh->mNumVertices; a++) { // if the vertex is unused Do nothing - if (usedVertexIndices.find(a) == usedVertexIndices.end()) { + if (0 == (usedVertexIndicesMask[a / 32] & (1u << (a % 32)))) { continue; } // collect the vertex data