summaryrefslogtreecommitdiff
path: root/lib/ds/plarena.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ds/plarena.c')
-rw-r--r--lib/ds/plarena.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c
index 1d54e2ca..3c6df2b7 100644
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -35,35 +35,40 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
* align = 1 to 32.
*/
static const PRUint8 pmasks[33] = {
- 0, /* not used */
- 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
+ 0, /* not used */
+ 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31 /* 17 ... 32 */
};
- if (align == 0)
+ if (align == 0) {
align = PL_ARENA_DEFAULT_ALIGN;
+ }
- if (align < sizeof(pmasks)/sizeof(pmasks[0]))
+ if (align < sizeof(pmasks)/sizeof(pmasks[0])) {
pool->mask = pmasks[align];
- else
+ }
+ else {
pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+ }
pool->first.next = NULL;
/* Set all three addresses in pool->first to the same dummy value.
* These addresses are only compared with each other, but never
* dereferenced. */
pool->first.base = pool->first.avail = pool->first.limit =
- (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
+ (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
pool->current = &pool->first;
/*
* Compute the net size so that each arena's gross size is |size|.
* sizeof(PLArena) + pool->mask is the header and alignment slop
* that PL_ArenaAllocate adds to the net size.
*/
- if (size > sizeof(PLArena) + pool->mask)
+ if (size > sizeof(PLArena) + pool->mask) {
pool->arenasize = size - (sizeof(PLArena) + pool->mask);
- else
+ }
+ else {
pool->arenasize = size;
+ }
#ifdef PL_ARENAMETER
memset(&pool->stats, 0, sizeof pool->stats);
pool->stats.name = strdup(name);
@@ -102,8 +107,9 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
nbOld = nb;
nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
- if (nb < nbOld)
+ if (nb < nbOld) {
return NULL;
+ }
/* attempt to allocate from arenas at pool->current */
{
@@ -139,8 +145,9 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
a->next = pool->current->next;
pool->current->next = a;
pool->current = a;
- if ( NULL == pool->first.next )
+ if ( NULL == pool->first.next ) {
pool->first.next = a;
+ }
PL_COUNT_ARENA(pool,++);
COUNT(pool, nmallocs);
return(rp);
@@ -156,11 +163,13 @@ PR_IMPLEMENT(void *) PL_ArenaGrow(
{
void *newp;
- if (PR_UINT32_MAX - size < incr)
+ if (PR_UINT32_MAX - size < incr) {
return NULL;
+ }
PL_ARENA_ALLOCATE(newp, pool, size + incr);
- if (newp)
+ if (newp) {
memcpy(newp, p, size);
+ }
return newp;
}
@@ -183,8 +192,9 @@ PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
static void FreeArenaList(PLArenaPool *pool, PLArena *head)
{
PLArena *a = head->next;
- if (!a)
+ if (!a) {
return;
+ }
head->next = NULL;
@@ -225,8 +235,9 @@ PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool)
{
PLArenaStats *stats, **statsp;
- if (pool->stats.name)
+ if (pool->stats.name) {
PR_DELETE(pool->stats.name);
+ }
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
statsp = &stats->next) {
if (stats == &pool->stats) {
@@ -267,8 +278,9 @@ PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
{
pool->stats.nallocs++;
pool->stats.nbytes += nb;
- if (nb > pool->stats.maxalloc)
+ if (nb > pool->stats.maxalloc) {
pool->stats.maxalloc = nb;
+ }
pool->stats.variance += nb * nb;
}
@@ -285,8 +297,9 @@ PR_IMPLEMENT(void) PL_ArenaCountGrowth(
pool->stats.nbytes += incr;
pool->stats.variance -= size * size;
size += incr;
- if (size > pool->stats.maxalloc)
+ if (size > pool->stats.maxalloc) {
pool->stats.maxalloc = size;
+ }
pool->stats.variance += size * size;
}