From: Robert Haas Date: Mon, 3 Feb 2014 17:49:29 +0000 (-0500) Subject: Hack. X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=09e1f49cc2dacf188bd71b1ca6923c198ea703d5;p=users%2Frhaas%2Fpostgres.git Hack. --- diff --git a/src/backend/utils/mmgr/mspan.c b/src/backend/utils/mmgr/mspan.c index c0a81e5253..6ad8cfcd4f 100644 --- a/src/backend/utils/mmgr/mspan.c +++ b/src/backend/utils/mmgr/mspan.c @@ -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; } /*