Hack.
authorRobert Haas <[email protected]>
Mon, 3 Feb 2014 17:49:29 +0000 (12:49 -0500)
committerRobert Haas <[email protected]>
Thu, 6 Feb 2014 14:23:01 +0000 (09:23 -0500)
src/backend/utils/mmgr/mspan.c

index c0a81e5253ceb38e1644ba2867b42d1df7114669..6ad8cfcd4fcbfd82df728d46e9559fc6bcba79f2 100644 (file)
@@ -502,6 +502,7 @@ static char *
 mspan_allocate_from_superblock(char *base, mspan *superblock)
 {
        char   *spanbase;
+       char   *result;
        uint16  object_size;
        uint16  total;
 
@@ -511,27 +512,26 @@ mspan_allocate_from_superblock(char *base, mspan *superblock)
        if (superblock->nused >= total)
                return NULL;
 
-       /* Try to reuse a previously-freed object. */
+       /* Do the allocation. */
        spanbase = base + superblock->first_page * MSPAN_PAGE_SIZE;
        if (superblock->firstfree != MSPAN_FIRSTFREE_NONE)
        {
-               uint16 *firstfree;
-
-               firstfree =
-                       (uint16 *) (spanbase + (superblock->firstfree * object_size));
-               superblock->firstfree = *firstfree;
-               return (char *) firstfree;
+               /* There's a freed object available for reuse.  Allocate it. */
+               result = spanbase + (superblock->firstfree * object_size);
+               superblock->firstfree = ((uint16 *) result)[0];
+       }
+       else
+       {
+               /* Carve out an object from not-previously-used part of span. */
+               result = spanbase + (superblock->ninitialized * object_size);
+               ++superblock->ninitialized;
        }
 
-       /*
-        * Carve out space from the uninitialized portion of the span.  This
-        * should always work, since we already verified that nused < total.
-        */
-
-       /*
-        * XXX. Implementation needed.
-        */
-       return NULL;
+       /* Update counter and return result. */
+       ++superblock->nused;
+       Assert(superblock->nused <= superblock->ninitialized);
+       Assert(result < spanbase + object_size * total);
+       return result;
 }
 
 /*