]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
ssfmalloc: Simplify.
authorBruno Haible <bruno@clisp.org>
Tue, 9 Dec 2025 22:39:04 +0000 (23:39 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Dec 2025 22:39:04 +0000 (23:39 +0100)
* lib/ssfmalloc.h (allocate_block_from_pool): Unify common code in
if/else branches.

ChangeLog
lib/ssfmalloc.h

index ddc47dff5817ef80bb6a7754c35271ad48e11103..59aa2c28ce457fa7f3da93bd7e0febf3897d42c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-09  Bruno Haible  <bruno@clisp.org>
+
+       ssfmalloc: Simplify.
+       * lib/ssfmalloc.h (allocate_block_from_pool): Unify common code in
+       if/else branches.
+
 2025-12-09  Bruno Haible  <bruno@clisp.org>
 
        string-desc: Remove unnecessary variable.
index f05f1504095a9c803552a602f4d66b9e41003668..0d7277cc6c540b6eb029eee2a5840fc75f315679 100644 (file)
@@ -762,50 +762,43 @@ allocate_block_from_pool (size_t size, struct page_pool *pool)
         }
       ((struct dissected_page_header *) page)->tree_element = element;
       pool->freeable_page = 0;
-
-      uintptr_t block = pool->allocate_block_in_page (size, page);
-      if (block == 0)
-        /* If the size is too large for an empty page, this function should not
-           have been invoked.  */
-        abort ();
-      add_update (page, pool);
-      pool->last_page = page;
-      return block;
     }
-
-  /* Allocate a fresh page.  */
-  page = ALLOC_PAGES (PAGESIZE);
-  if (unlikely (page == 0))
+  else
     {
-      /* Failed.  */
-      pool->last_page = 0;
-      return 0;
-    }
-  if ((page & (PAGESIZE - 1)) != 0)
-    /* ALLOC_PAGES's result is not aligned as expected.  */
-    abort ();
+      /* Allocate a fresh page.  */
+      page = ALLOC_PAGES (PAGESIZE);
+      if (unlikely (page == 0))
+        {
+          /* Failed.  */
+          pool->last_page = 0;
+          return 0;
+        }
+      if ((page & (PAGESIZE - 1)) != 0)
+        /* ALLOC_PAGES's result is not aligned as expected.  */
+        abort ();
 
-  pool->init_page (page);
-  struct page_tree_element *element =
-    (struct page_tree_element *) malloc (sizeof (struct page_tree_element));
-  if (unlikely (element == NULL))
-    {
-      /* Could not allocate the tree element.  */
-      FREE_PAGES (page, PAGESIZE);
-      pool->last_page = 0;
-      return 0;
-    }
-  element->page = page;
-  element->free_space = ((struct dissected_page_header *) page)->free_space;
-  if (unlikely (gl_oset_nx_add (pool->managed_pages, element) < 0))
-    {
-      /* Could not allocate the tree node.  */
-      free (element);
-      FREE_PAGES (page, PAGESIZE);
-      pool->last_page = 0;
-      return 0;
+      pool->init_page (page);
+      struct page_tree_element *element =
+        (struct page_tree_element *) malloc (sizeof (struct page_tree_element));
+      if (unlikely (element == NULL))
+        {
+          /* Could not allocate the tree element.  */
+          FREE_PAGES (page, PAGESIZE);
+          pool->last_page = 0;
+          return 0;
+        }
+      element->page = page;
+      element->free_space = ((struct dissected_page_header *) page)->free_space;
+      if (unlikely (gl_oset_nx_add (pool->managed_pages, element) < 0))
+        {
+          /* Could not allocate the tree node.  */
+          free (element);
+          FREE_PAGES (page, PAGESIZE);
+          pool->last_page = 0;
+          return 0;
+        }
+      ((struct dissected_page_header *) page)->tree_element = element;
     }
-  ((struct dissected_page_header *) page)->tree_element = element;
 
   uintptr_t block = pool->allocate_block_in_page (size, page);
   if (block == 0)