src/mempool.c

changeset 1065
6eb7b54975ee
parent 1040
1ecf4dbbc60c
--- a/src/mempool.c	Sun Dec 29 15:24:20 2024 +0100
+++ b/src/mempool.c	Sun Dec 29 16:56:13 2024 +0100
@@ -53,17 +53,13 @@
             return NULL;
         }
         struct cx_mempool_memory_s **newdata = realloc(pool->data, newmsize);
-        if (newdata == NULL) {
-            return NULL;
-        }
+        if (newdata == NULL) return NULL;
         pool->data = newdata;
         pool->capacity = newcap;
     }
 
     struct cx_mempool_memory_s *mem = malloc(sizeof(cx_destructor_func) + n);
-    if (mem == NULL) {
-        return NULL;
-    }
+    if (mem == NULL) return NULL;
 
     mem->destructor = pool->auto_destr;
     pool->data[pool->size] = mem;
@@ -83,9 +79,7 @@
         return NULL;
     }
     void *ptr = cx_mempool_malloc(p, msz);
-    if (ptr == NULL) {
-        return NULL;
-    }
+    if (ptr == NULL) return NULL;
     memset(ptr, 0, nelem * elsize);
     return ptr;
 }
@@ -101,9 +95,7 @@
     mem = (struct cx_mempool_memory_s*)(((char *) ptr) - sizeof(cx_destructor_func));
     newm = realloc(mem, n + sizeof(cx_destructor_func));
 
-    if (newm == NULL) {
-        return NULL;
-    }
+    if (newm == NULL) return NULL;
     if (mem != newm) {
         for (size_t i = 0; i < pool->size; i++) {
             if (pool->data[i] == mem) {
@@ -111,7 +103,7 @@
                 return ((char*)newm) + sizeof(cx_destructor_func);
             }
         }
-        abort();
+        abort(); // LCOV_EXCL_LINE
     } else {
         return ptr;
     }
@@ -142,7 +134,7 @@
             return;
         }
     }
-    abort();
+    abort(); // LCOV_EXCL_LINE
 }
 
 void cxMempoolFree(CxMempool *pool) {
@@ -218,30 +210,28 @@
 
     struct cx_mempool_s *pool =
             malloc(sizeof(struct cx_mempool_s));
-    if (pool == NULL) {
-        return NULL;
-    }
+    if (pool == NULL) return NULL;
 
     CxAllocator *provided_allocator = malloc(sizeof(CxAllocator));
-    if (provided_allocator == NULL) {
+    if (provided_allocator == NULL) { // LCOV_EXCL_START
         free(pool);
         return NULL;
-    }
+    } // LCOV_EXCL_STOP
     provided_allocator->cl = &cx_mempool_allocator_class;
     provided_allocator->data = pool;
 
     pool->allocator = provided_allocator;
 
     pool->data = malloc(poolsize);
-    if (pool->data == NULL) {
+    if (pool->data == NULL) { // LCOV_EXCL_START
         free(provided_allocator);
         free(pool);
         return NULL;
-    }
+    } // LCOV_EXCL_STOP
 
     pool->size = 0;
     pool->capacity = capacity;
     pool->auto_destr = destr;
 
-    return (CxMempool *) pool;
+    return pool;
 }

mercurial