Skip to content

Commit

Permalink
Merge pull request #4710 from WalterBright/dtcodepool
Browse files Browse the repository at this point in the history
use pools for dt_t and code allocation
  • Loading branch information
andralex committed Jun 2, 2015
2 parents 7d4e2e8 + 7adb348 commit 55d7491
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
43 changes: 29 additions & 14 deletions src/backend/code.c
@@ -1,5 +1,5 @@
// Copyright (C) 1987-1998 by Symantec
// Copyright (C) 2000-2013 by Digital Mars
// Copyright (C) 2000-2015 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand Down Expand Up @@ -30,11 +30,20 @@ code *code_calloc()
{
//printf("code %d\n", sizeof(code));
code *c = code_list;
if (c)
code_list = code_next(c);
else
c = (code *)mem_fmalloc(sizeof(*c));
if (!c)
{
const size_t n = 4096 / sizeof(*c);
code *chunk = (code *)mem_fmalloc(n * sizeof(code));
for (size_t i = 0; i < n - 1; ++i)
{
code_next(&chunk[i]) = &chunk[i + 1];
}
code_next(&chunk[n - 1]) = NULL;
code_list = chunk;
c = chunk;
}

code_list = code_next(c);
MEMCLEAR(c, sizeof(*c));

//dbg_printf("code_calloc: %p\n",c);
Expand All @@ -47,18 +56,24 @@ code *code_calloc()
*/

void code_free(code *cstart)
{ code **pc;
code *c;

for (pc = &cstart; (c = *pc) != NULL; pc = &code_next(c))
{
if (cstart)
{
if (c->Iop == ASM)
code *c = cstart;
while (1)
{
mem_free(c->IEV1.as.bytes);
if (c->Iop == ASM)
{
mem_free(c->IEV1.as.bytes);
}
code *cnext = code_next(c);
if (!cnext)
break;
c = cnext;
}
code_next(c) = code_list;
code_list = cstart;
}
*pc = code_list;
code_list = cstart;
}

/*****************
Expand All @@ -73,7 +88,7 @@ void code_term()

while (code_list)
{ cn = code_next(code_list);
mem_ffree(code_list);
//mem_ffree(code_list);
code_list = cn;
count++;
}
Expand Down
54 changes: 34 additions & 20 deletions src/backend/dt.c
@@ -1,5 +1,5 @@
// Copyright (C) 1984-1998 by Symantec
// Copyright (C) 2000-2013 by Digital Mars
// Copyright (C) 2000-2015 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand Down Expand Up @@ -33,17 +33,25 @@ static dt_t *dt_freelist;

static dt_t *dt_calloc(int dtx)
{
dt_t *dt;
static dt_t dtzero;

if (dt_freelist)
dt_t *dt = dt_freelist;
if (!dt)
{
dt = dt_freelist;
dt_freelist = dt->DTnext;
*dt = dtzero;
const size_t n = 4096 / sizeof(dt_t);
dt_t *chunk = (dt_t *)mem_fmalloc(n * sizeof(dt_t));
for (size_t i = 0; i < n - 1; ++i)
{
chunk[i].DTnext = &chunk[i + 1];
}
chunk[n - 1].DTnext = NULL;
dt_freelist = chunk;
dt = chunk;
}
else
dt = (dt_t *) mem_fcalloc(sizeof(dt_t));

dt_freelist = dt->DTnext;
#ifdef DEBUG
memset(dt, 0xBE, sizeof(*dt));
#endif
dt->DTnext = NULL;
dt->dt = dtx;
return dt;
}
Expand All @@ -53,19 +61,25 @@ static dt_t *dt_calloc(int dtx)
*/

void dt_free(dt_t *dt)
{ dt_t *dtn;

for (; dt; dt = dtn)
{
if (dt)
{
switch (dt->dt)
dt_t *dtn = dt;
while (1)
{
case DT_abytes:
case DT_nbytes:
mem_free(dt->DTpbytes);
switch (dtn->dt)
{
case DT_abytes:
case DT_nbytes:
mem_free(dtn->DTpbytes);
break;
}
dt_t *dtnext = dtn->DTnext;
if (!dtnext)
break;
dtn = dtnext;
}
dtn = dt->DTnext;
dt->DTnext = dt_freelist;
dtn->DTnext = dt_freelist;
dt_freelist = dt;
}
}
Expand All @@ -76,7 +90,7 @@ void dt_free(dt_t *dt)

void dt_term()
{
#if TERMCODE
#if 0 && TERMCODE
dt_t *dtn;

while (dt_freelist)
Expand Down

0 comments on commit 55d7491

Please sign in to comment.