Skip to content

Commit

Permalink
Merge pull request #4716 from WalterBright/codeinline
Browse files Browse the repository at this point in the history
small speedup in code allocation
  • Loading branch information
9rnsr committed Jul 1, 2015
2 parents 1ceb899 + b7e3639 commit 08aaba0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/backend/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ code *gen(code *c,code *cs)
#if TX86
assert(I64 || cs->Irex == 0);
#endif
code* ce = code_calloc();
code* ce = code_malloc();
*ce = *cs;
//printf("ce = %p %02x\n", ce, ce->Iop);
ccheck(ce);
Expand Down
34 changes: 19 additions & 15 deletions src/backend/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@
#include "code.h"
#include "global.h"

static code *code_list;
code *code_list = NULL;

/************************************
* Allocate a chunk of code's and add them to
* code_list.
*/
code *code_chunk_alloc()
{
const size_t n = 4096 / sizeof(code);
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;
return chunk;
}

/*****************
* Allocate code
Expand All @@ -29,20 +46,7 @@ static code *code_list;
code *code_calloc()
{
//printf("code %d\n", sizeof(code));
code *c = code_list;
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 *c = code_list ? code_list : code_chunk_alloc();
code_list = code_next(c);
MEMCLEAR(c, sizeof(*c));

Expand Down
18 changes: 15 additions & 3 deletions src/backend/code.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 1985-1996 by Symantec
// Copyright (C) 2000-2012 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 @@ -75,12 +75,24 @@ union evc

/********************** PUBLIC FUNCTIONS *******************/

code *code_calloc(void);
code *code_calloc();
void code_free (code *);
void code_term(void);
void code_term();

#define code_next(c) ((c)->next)

code *code_chunk_alloc();
extern code *code_list;
inline code *code_malloc()
{
//printf("code %d\n", sizeof(code));
code *c = code_list ? code_list : code_chunk_alloc();
code_list = code_next(c);
//printf("code_malloc: %p\n",c);
return c;
}


extern con_t regcon;

/****************************
Expand Down

0 comments on commit 08aaba0

Please sign in to comment.