mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-07 21:50:08 +01:00
Global: major FFlist related code refactor
This commit is contained in:
@@ -55,11 +55,3 @@ bool ffListPop(FFlist* list, void* result)
|
||||
--list->length;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ffListDestroy(FFlist* list)
|
||||
{
|
||||
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
|
||||
list->capacity = list->length = 0;
|
||||
free(list->data);
|
||||
list->data = NULL;
|
||||
}
|
||||
|
||||
+21
-3
@@ -31,12 +31,20 @@ bool ffListShift(FFlist* list, void* result);
|
||||
// Removes the last element, and copy its value to `*result`
|
||||
bool ffListPop(FFlist* list, void* result);
|
||||
|
||||
void ffListDestroy(FFlist* list);
|
||||
|
||||
static inline void ffListInit(FFlist* list, uint32_t elementSize)
|
||||
{
|
||||
assert(elementSize > 0);
|
||||
ffListInitA(list, elementSize, 0);
|
||||
list->elementSize = elementSize;
|
||||
list->capacity = 0;
|
||||
list->length = 0;
|
||||
list->data = NULL;
|
||||
}
|
||||
|
||||
static inline FFlist ffListCreate(uint32_t elementSize)
|
||||
{
|
||||
FFlist result;
|
||||
ffListInit(&result, elementSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void* ffListGet(const FFlist* list, uint32_t index)
|
||||
@@ -50,6 +58,16 @@ static inline void ffListSort(FFlist* list, int(*compar)(const void*, const void
|
||||
qsort(list->data, list->length, list->elementSize, compar);
|
||||
}
|
||||
|
||||
static inline void ffListDestroy(FFlist* list)
|
||||
{
|
||||
if (!list->data) return;
|
||||
|
||||
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
|
||||
list->capacity = list->length = 0;
|
||||
free(list->data);
|
||||
list->data = NULL;
|
||||
}
|
||||
|
||||
#define FF_LIST_FOR_EACH(itemType, itemVarName, listVar) \
|
||||
assert(sizeof(itemType) == (listVar).elementSize); \
|
||||
for(itemType* itemVarName = (itemType*)(listVar).data; \
|
||||
|
||||
Reference in New Issue
Block a user