From b26cd6a4b9008836f9d764489b4aac5e143ad611 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 26 Dec 2023 09:10:33 -0500 Subject: [PATCH] Cleanup: Remove unused GSQueue container GSQueue dates back over 21 years, past the initial git commit. Nowadays we generally prefer to use data structures from the C++ standard library or our own C++ data structures. Previous commits replaced this container with `std::queue` in a few areas. Now it is unused and can be removed. --- intern/ghost/test/CMakeLists.txt | 1 - source/blender/blenlib/BLI_gsqueue.h | 48 ----- source/blender/blenlib/CMakeLists.txt | 2 - source/blender/blenlib/intern/gsqueue.c | 164 ------------------ source/blender/makesdna/intern/CMakeLists.txt | 1 - 5 files changed, 216 deletions(-) delete mode 100644 source/blender/blenlib/BLI_gsqueue.h delete mode 100644 source/blender/blenlib/intern/gsqueue.c diff --git a/intern/ghost/test/CMakeLists.txt b/intern/ghost/test/CMakeLists.txt index e6896fbbaf4..2bd5ee48661 100644 --- a/intern/ghost/test/CMakeLists.txt +++ b/intern/ghost/test/CMakeLists.txt @@ -165,7 +165,6 @@ add_definitions(-DMATH_STANDALONE) add_library(bli_lib "../../../source/blender/blenlib/intern/fileops.c" - "../../../source/blender/blenlib/intern/gsqueue.c" "../../../source/blender/blenlib/intern/rct.c" "../../../source/blender/blenlib/intern/string.c" "../../../source/blender/blenlib/intern/string_utf8.c" diff --git a/source/blender/blenlib/BLI_gsqueue.h b/source/blender/blenlib/BLI_gsqueue.h deleted file mode 100644 index 02c0527a0a6..00000000000 --- a/source/blender/blenlib/BLI_gsqueue.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved. - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -/** \file - * \ingroup bli - */ - -#include "BLI_utildefines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _GSQueue GSQueue; - -GSQueue *BLI_gsqueue_new(size_t elem_size); -/** - * Returns true if the queue is empty, false otherwise. - */ -bool BLI_gsqueue_is_empty(const GSQueue *queue); -size_t BLI_gsqueue_len(const GSQueue *queue); -/** - * Retrieves and removes the first element from the queue. - * The value is copies to \a r_item, which must be at least \a elem_size bytes. - * - * Does not reduce amount of allocated memory. - */ -void BLI_gsqueue_pop(GSQueue *queue, void *r_item); -/** - * Copies the source value onto the end of the queue - * - * \note This copies #GSQueue.elem_size bytes from \a item, - * (the pointer itself is not stored). - * - * \param item: source data to be copied to the queue. - */ -void BLI_gsqueue_push(GSQueue *queue, const void *item); -/** - * Free the queue's data and the queue itself. - */ -void BLI_gsqueue_free(GSQueue *queue); - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 3de5abb69e9..faef5fb9d09 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -76,7 +76,6 @@ set(SRC intern/generic_vector_array.cc intern/generic_virtual_array.cc intern/generic_virtual_vector_array.cc - intern/gsqueue.c intern/hash_md5.c intern/hash_mm2a.c intern/hash_mm3.c @@ -239,7 +238,6 @@ set(SRC BLI_generic_virtual_array.hh BLI_generic_virtual_vector_array.hh BLI_ghash.h - BLI_gsqueue.h BLI_hash.h BLI_hash.hh BLI_hash_md5.h diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c deleted file mode 100644 index 55cfbd65655..00000000000 --- a/source/blender/blenlib/intern/gsqueue.c +++ /dev/null @@ -1,164 +0,0 @@ -/* SPDX-FileCopyrightText: 2023 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -/** \file - * \ingroup bli - * - * \brief A generic structure queue - * (a queue for fixed length generally small) structures. - */ - -#include - -#include "MEM_guardedalloc.h" - -#include "BLI_gsqueue.h" -#include "BLI_strict_flags.h" -#include "BLI_utildefines.h" - -/* target chunk size: 64kb */ -#define CHUNK_SIZE_DEFAULT (1 << 16) -/* ensure we get at least this many elems per chunk */ -#define CHUNK_ELEM_MIN 32 - -struct QueueChunk { - struct QueueChunk *next; - char data[0]; -}; - -struct _GSQueue { - struct QueueChunk *chunk_first; /* first active chunk to pop from */ - struct QueueChunk *chunk_last; /* last active chunk to push onto */ - struct QueueChunk *chunk_free; /* free chunks to reuse */ - size_t chunk_first_index; /* index into 'chunk_first' */ - size_t chunk_last_index; /* index into 'chunk_last' */ - size_t chunk_elem_max; /* number of elements per chunk */ - size_t elem_size; /* memory size of elements */ - size_t elem_num; /* total number of elements */ -}; - -static void *queue_get_first_elem(GSQueue *queue) -{ - return ((char *)(queue)->chunk_first->data) + ((queue)->elem_size * (queue)->chunk_first_index); -} - -static void *queue_get_last_elem(GSQueue *queue) -{ - return ((char *)(queue)->chunk_last->data) + ((queue)->elem_size * (queue)->chunk_last_index); -} - -/** - * \return number of elements per chunk, optimized for slop-space. - */ -static size_t queue_chunk_elem_max_calc(const size_t elem_size, size_t chunk_size) -{ - /* get at least this number of elems per chunk */ - const size_t elem_size_min = elem_size * CHUNK_ELEM_MIN; - - BLI_assert((elem_size != 0) && (chunk_size != 0)); - - while (UNLIKELY(chunk_size <= elem_size_min)) { - chunk_size <<= 1; - } - - /* account for slop-space */ - chunk_size -= (sizeof(struct QueueChunk) + MEM_SIZE_OVERHEAD); - - return chunk_size / elem_size; -} - -GSQueue *BLI_gsqueue_new(const size_t elem_size) -{ - GSQueue *queue = MEM_callocN(sizeof(*queue), "BLI_gsqueue_new"); - - queue->chunk_elem_max = queue_chunk_elem_max_calc(elem_size, CHUNK_SIZE_DEFAULT); - queue->elem_size = elem_size; - /* force init */ - queue->chunk_last_index = queue->chunk_elem_max - 1; - - return queue; -} - -static void queue_free_chunk(struct QueueChunk *data) -{ - while (data) { - struct QueueChunk *data_next = data->next; - MEM_freeN(data); - data = data_next; - } -} - -void BLI_gsqueue_free(GSQueue *queue) -{ - queue_free_chunk(queue->chunk_first); - queue_free_chunk(queue->chunk_free); - MEM_freeN(queue); -} - -void BLI_gsqueue_push(GSQueue *queue, const void *item) -{ - queue->chunk_last_index++; - queue->elem_num++; - - if (UNLIKELY(queue->chunk_last_index == queue->chunk_elem_max)) { - struct QueueChunk *chunk; - if (queue->chunk_free) { - chunk = queue->chunk_free; - queue->chunk_free = chunk->next; - } - else { - chunk = MEM_mallocN(sizeof(*chunk) + (queue->elem_size * queue->chunk_elem_max), __func__); - } - - chunk->next = NULL; - - if (queue->chunk_last == NULL) { - queue->chunk_first = chunk; - } - else { - queue->chunk_last->next = chunk; - } - - queue->chunk_last = chunk; - queue->chunk_last_index = 0; - } - - BLI_assert(queue->chunk_last_index < queue->chunk_elem_max); - - /* Return last of queue */ - memcpy(queue_get_last_elem(queue), item, queue->elem_size); -} - -void BLI_gsqueue_pop(GSQueue *queue, void *r_item) -{ - BLI_assert(BLI_gsqueue_is_empty(queue) == false); - - memcpy(r_item, queue_get_first_elem(queue), queue->elem_size); - queue->chunk_first_index++; - queue->elem_num--; - - if (UNLIKELY(queue->chunk_first_index == queue->chunk_elem_max || queue->elem_num == 0)) { - struct QueueChunk *chunk_free = queue->chunk_first; - - queue->chunk_first = queue->chunk_first->next; - queue->chunk_first_index = 0; - if (queue->chunk_first == NULL) { - queue->chunk_last = NULL; - queue->chunk_last_index = queue->chunk_elem_max - 1; - } - - chunk_free->next = queue->chunk_free; - queue->chunk_free = chunk_free; - } -} - -size_t BLI_gsqueue_len(const GSQueue *queue) -{ - return queue->elem_num; -} - -bool BLI_gsqueue_is_empty(const GSQueue *queue) -{ - return (queue->chunk_first == NULL); -} diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index 7fe53d2f044..dabdfbe9e3d 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -60,7 +60,6 @@ set(SRC_BLENLIB ../../blenlib/intern/hash_mm2a.c # Dependencies of BLI_mempool.c when ASAN is enabled. - ../../blenlib/intern/gsqueue.c ../../blenlib/intern/threads.cc ../../blenlib/intern/time.c )