ucx/mempool.c

branch
dav-2
changeset 889
42cdbf9bbd49
parent 886
da79af4baec8
--- a/ucx/mempool.c	Tue Oct 14 21:02:26 2025 +0200
+++ b/ucx/mempool.c	Sat Nov 08 23:06:11 2025 +0100
@@ -116,6 +116,9 @@
     if (!ptr) return;
     struct cx_mempool_s *pool = p;
 
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
+
     struct cx_mempool_memory_s *mem =
         (void*) ((char *) ptr - sizeof(struct cx_mempool_memory_s));
 
@@ -124,11 +127,11 @@
             if (mem->destructor) {
                 mem->destructor(mem->c);
             }
-            if (pool->destr) {
-                pool->destr(mem->c);
+            if (destr != NULL) {
+                destr(mem->c);
             }
-            if (pool->destr2) {
-                pool->destr2(pool->destr2_data, mem->c);
+            if (destr2 != NULL) {
+                destr2(pool->destr2_data, mem->c);
             }
             cxFree(pool->base_allocator, mem);
             size_t last_index = pool->size - 1;
@@ -179,18 +182,18 @@
 }
 
 static void cx_mempool_free_all_simple(const struct cx_mempool_s *pool) {
-    const bool has_destr = pool->destr;
-    const bool has_destr2 = pool->destr2;
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
     for (size_t i = 0; i < pool->size; i++) {
         struct cx_mempool_memory_s *mem = pool->data[i];
         if (mem->destructor) {
             mem->destructor(mem->c);
         }
-        if (has_destr) {
-            pool->destr(mem->c);
+        if (destr != NULL) {
+            destr(mem->c);
         }
-        if (has_destr2) {
-            pool->destr2(pool->destr2_data, mem->c);
+        if (destr2 != NULL) {
+            destr2(pool->destr2_data, mem->c);
         }
         cxFree(pool->base_allocator, mem);
     }
@@ -247,6 +250,9 @@
     if (!ptr) return;
     struct cx_mempool_s *pool = p;
 
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
+
     struct cx_mempool_memory2_s *mem =
         (void*) ((char *) ptr - sizeof(struct cx_mempool_memory2_s));
 
@@ -255,11 +261,11 @@
             if (mem->destructor) {
                 mem->destructor(mem->data, mem->c);
             }
-            if (pool->destr) {
-                pool->destr(mem->c);
+            if (destr != NULL) {
+                destr(mem->c);
             }
-            if (pool->destr2) {
-                pool->destr2(pool->destr2_data, mem->c);
+            if (destr2 != NULL) {
+                destr2(pool->destr2_data, mem->c);
             }
             cxFree(pool->base_allocator, mem);
             size_t last_index = pool->size - 1;
@@ -310,18 +316,18 @@
 }
 
 static void cx_mempool_free_all_advanced(const struct cx_mempool_s *pool) {
-    const bool has_destr = pool->destr;
-    const bool has_destr2 = pool->destr2;
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
     for (size_t i = 0; i < pool->size; i++) {
         struct cx_mempool_memory2_s *mem = pool->data[i];
         if (mem->destructor) {
             mem->destructor(mem->data, mem->c);
         }
-        if (has_destr) {
-            pool->destr(mem->c);
+        if (destr != NULL) {
+            destr(mem->c);
         }
-        if (has_destr2) {
-            pool->destr2(pool->destr2_data, mem->c);
+        if (destr2 != NULL) {
+            destr2(pool->destr2_data, mem->c);
         }
         cxFree(pool->base_allocator, mem);
     }
@@ -376,13 +382,16 @@
     if (!ptr) return;
     struct cx_mempool_s *pool = p;
 
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
+
     for (size_t i = 0; i < pool->size; i++) {
         if (ptr == pool->data[i]) {
-            if (pool->destr) {
-                pool->destr(ptr);
+            if (destr != NULL) {
+                destr(ptr);
             }
-            if (pool->destr2) {
-                pool->destr2(pool->destr2_data, ptr);
+            if (destr2 != NULL) {
+                destr2(pool->destr2_data, ptr);
             }
             cxFree(pool->base_allocator, ptr);
             size_t last_index = pool->size - 1;
@@ -427,15 +436,15 @@
 }
 
 static void cx_mempool_free_all_pure(const struct cx_mempool_s *pool) {
-    const bool has_destr = pool->destr;
-    const bool has_destr2 = pool->destr2;
+    cx_destructor_func destr = pool->destr;
+    cx_destructor_func2 destr2 = pool->destr2;
     for (size_t i = 0; i < pool->size; i++) {
         void *mem = pool->data[i];
-        if (has_destr) {
-            pool->destr(mem);
+        if (destr != NULL) {
+            destr(mem);
         }
-        if (has_destr2) {
-            pool->destr2(pool->destr2_data, mem);
+        if (destr2 != NULL) {
+            destr2(pool->destr2_data, mem);
         }
         cxFree(pool->base_allocator, mem);
     }

mercurial