summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/blockarr.c15
-rw-r--r--util/err.c16
2 files changed, 16 insertions, 15 deletions
diff --git a/util/blockarr.c b/util/blockarr.c
index c85df5a..03d44b2 100644
--- a/util/blockarr.c
+++ b/util/blockarr.c
@@ -21,13 +21,13 @@ typedef struct {
Note: the block size must be a power of 2, to use right shifting instead of division
(for optimization)!
*/
-void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) {
+static void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) {
arr_create(&arr->blocks, sizeof(ArrBlock));
arr->item_sz = item_sz;
arr->lg_block_sz = lg_block_sz;
}
-void *block_arr_add(BlockArr *arr) {
+static void *block_arr_add(BlockArr *arr) {
ArrBlock *last_block;
last_block = arr_last(&arr->blocks);
@@ -46,12 +46,13 @@ void *block_arr_add(BlockArr *arr) {
}
}
-/* Don't need this yet. */
-/* void *block_arr_get(BlockArr *arr, size_t index) { */
-
-/* } */
+static inline void *block_arr_get(BlockArr *arr, size_t index) {
+ size_t block_index = index >> arr->lg_block_sz;
+ ArrBlock *block = (ArrBlock*)arr->blocks.data + block_index;
+ return (char*)block->data + arr->item_sz * index;
+}
-void block_arr_free(BlockArr *arr) {
+static void block_arr_free(BlockArr *arr) {
arr_foreach(&arr->blocks, ArrBlock, block) {
free(block->data);
}
diff --git a/util/err.c b/util/err.c
index e53b16f..1a05e9d 100644
--- a/util/err.c
+++ b/util/err.c
@@ -111,14 +111,14 @@ static void *err_malloc(size_t size) {
return ret;
}
-static void *err_calloc(size_t n, size_t size) {
- void *ret = calloc(n, size);
- if (!ret) {
- fprintf(stderr, "Error: Out of memory.\n");
- abort();
- }
- return ret;
-}
+/* static void *err_calloc(size_t n, size_t size) { */
+/* void *ret = calloc(n, size); */
+/* if (!ret) { */
+/* fprintf(stderr, "Error: Out of memory.\n"); */
+/* abort(); */
+/* } */
+/* return ret; */
+/* } */
static void *err_realloc(void *data, size_t new_size) {
void *ret = realloc(data, new_size);