Improve calc perf

This commit is contained in:
Nic Barker 2024-11-27 11:30:36 +13:00
parent c8460acbae
commit 1d7b27a877

8
clay.h
View File

@ -1570,10 +1570,14 @@ Clay__MeasureTextCacheItem *Clay__MeasureTextCached(Clay_String *text, Clay_Text
// This element hasn't been seen in a few frames, delete the hash map item // This element hasn't been seen in a few frames, delete the hash map item
if (Clay__generation - hashEntry->generation > 2) { if (Clay__generation - hashEntry->generation > 2) {
// Add all the measured words that were included in this measurement to the freelist // Add all the measured words that were included in this measurement to the freelist
if (hashEntry->measuredWords.length > 0) {
uint32_t startOffset = hashEntry->measuredWords.internalArray - Clay__measuredWords.internalArray;
for (int32_t i = 0; i < hashEntry->measuredWords.length; i++) { for (int32_t i = 0; i < hashEntry->measuredWords.length; i++) {
uint32_t index = Clay__MeasuredWordArraySlice_Get(&hashEntry->measuredWords, i) - &Clay__measuredWords.internalArray[0]; Clay__int32_tArray_Add(&Clay__measuredWordsFreeList, (int32_t)(startOffset + i));
Clay__int32_tArray_Add(&Clay__measuredWordsFreeList, index);
} }
}
uint32_t nextIndex = hashEntry->nextIndex; uint32_t nextIndex = hashEntry->nextIndex;
Clay__MeasureTextCacheItemArray_Set(&Clay__measureTextHashMapInternal, elementIndex, CLAY__INIT(Clay__MeasureTextCacheItem) {}); Clay__MeasureTextCacheItemArray_Set(&Clay__measureTextHashMapInternal, elementIndex, CLAY__INIT(Clay__MeasureTextCacheItem) {});
Clay__int32_tArray_Add(&Clay__measureTextHashMapInternalFreeList, elementIndex); Clay__int32_tArray_Add(&Clay__measureTextHashMapInternalFreeList, elementIndex);