diff --git a/clay.h b/clay.h index 315edf0..6d3ee18 100644 --- a/clay.h +++ b/clay.h @@ -4750,29 +4750,29 @@ Clay_RenderCommandArray Clay_EndLayout(float deltaTime) { for (int i = 0; i < context->layoutElementsHashMap.capacity; ++i) { int32_t currentElementIndex = context->layoutElementsHashMap.internalArray[i]; int32_t previousElementIndex = -1; - int32_t listDepth = 0; while (currentElementIndex != -1) { Clay_LayoutElementHashMapItem* currentItem = Clay__LayoutElementHashMapItemArray_Get(&context->layoutElementsHashMapInternal, currentElementIndex); int32_t nextIndex = currentItem->nextIndex; // Needs to be pruned if (currentItem->generation <= context->generation) { + // Delete the underlying item and add it to the freelist + Clay__LayoutElementHashMapItemArray_Set(&context->layoutElementsHashMapInternal, currentElementIndex, CLAY__INIT(Clay_LayoutElementHashMapItem) { .nextIndex = -1 }); + Clay__int32_tArray_Add(&context->layoutElementsHashMapFreeList, currentElementIndex); // If it's the very top of the bucket, rewrite the first bucket pointer - if (listDepth == 0) { + if (previousElementIndex == -1) { Clay__int32_tArray_Set(&context->layoutElementsHashMap, i, nextIndex); - listDepth--; + currentElementIndex = nextIndex; + previousElementIndex = -1; } else { // Rewrite previous pointer Clay_LayoutElementHashMapItem* previousItem = Clay__LayoutElementHashMapItemArray_Get(&context->layoutElementsHashMapInternal, previousElementIndex); previousItem->nextIndex = nextIndex; + currentElementIndex = nextIndex; } - // Delete the underlying item and add it to the freelist - Clay__LayoutElementHashMapItemArray_Set(&context->layoutElementsHashMapInternal, currentElementIndex, CLAY__INIT(Clay_LayoutElementHashMapItem) { .nextIndex = -1 }); - Clay__int32_tArray_Add(&context->layoutElementsHashMapFreeList, currentElementIndex); + } else { + previousElementIndex = currentElementIndex; + currentElementIndex = nextIndex; } - - previousElementIndex = currentElementIndex; - currentElementIndex = nextIndex; - listDepth++; } }