mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00
Revert "Manage AST NODEs out of GC"
This reverts commit 620ba74778
.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
620ba74778
commit
5a176b75b1
10 changed files with 68 additions and 250 deletions
104
node.c
104
node.c
|
@ -1211,107 +1211,3 @@ rb_gc_mark_node(NODE *obj)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct node_buffer_elem_struct {
|
||||
struct node_buffer_elem_struct *next;
|
||||
NODE buf[1];
|
||||
} node_buffer_elem_t;
|
||||
|
||||
typedef struct node_buffer_struct {
|
||||
long idx, len;
|
||||
node_buffer_elem_t *head;
|
||||
node_buffer_elem_t body;
|
||||
} node_buffer_t;
|
||||
|
||||
node_buffer_t *
|
||||
rb_node_buffer_new()
|
||||
{
|
||||
node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + 16 * sizeof(NODE));
|
||||
nb->idx = 0;
|
||||
nb->len = 16;
|
||||
nb->head = &nb->body;
|
||||
nb->head->next = NULL;
|
||||
return nb;
|
||||
}
|
||||
|
||||
void
|
||||
rb_node_buffer_free(node_buffer_t *nb)
|
||||
{
|
||||
node_buffer_elem_t *nbe = nb->head;
|
||||
|
||||
while (nbe != &nb->body) {
|
||||
void *buf = nbe;
|
||||
nbe = nbe->next;
|
||||
xfree(buf);
|
||||
}
|
||||
xfree(nb);
|
||||
}
|
||||
|
||||
NODE *
|
||||
rb_ast_newnode(ast_t *ast)
|
||||
{
|
||||
node_buffer_t *nb = ast->node_buffer;
|
||||
if (nb->idx >= nb->len) {
|
||||
long n = nb->len * 2;
|
||||
node_buffer_elem_t *nbe;
|
||||
nbe = xmalloc(sizeof(node_buffer_elem_t) + n * sizeof(NODE));
|
||||
nb->idx = 0;
|
||||
nb->len = n;
|
||||
nbe->next = nb->head;
|
||||
nb->head = nbe;
|
||||
}
|
||||
return &nb->head->buf[nb->idx++];
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_delete_node(ast_t *ast, NODE *n)
|
||||
{
|
||||
(void)ast;
|
||||
(void)n;
|
||||
/* should we implement freelist? */
|
||||
}
|
||||
|
||||
ast_t *
|
||||
rb_ast_new(void)
|
||||
{
|
||||
return (ast_t *)rb_imemo_new(imemo_ast, 0, (VALUE)rb_node_buffer_new(), rb_ary_tmp_new(0), 0);
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_mark(ast_t *ast)
|
||||
{
|
||||
if (ast->node_buffer) rb_gc_mark(ast->mark_ary);
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_free(ast_t *ast)
|
||||
{
|
||||
if (ast->node_buffer) rb_node_buffer_free(ast->node_buffer);
|
||||
ast->node_buffer = 0;
|
||||
ast->root = 0;
|
||||
ast->mark_ary = 0;
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_dispose(ast_t *ast)
|
||||
{
|
||||
rb_ast_free(ast);
|
||||
rb_gc_writebarrier_remember((VALUE)ast);
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_add_mark_object(ast_t *ast, VALUE obj)
|
||||
{
|
||||
rb_ary_push(ast->mark_ary, obj);
|
||||
}
|
||||
|
||||
void
|
||||
rb_ast_delete_mark_object(ast_t *ast, VALUE obj)
|
||||
{
|
||||
long i;
|
||||
for (i = 0; i < RARRAY_LEN(ast->mark_ary); i++) {
|
||||
if (obj == RARRAY_AREF(ast->mark_ary, i)) {
|
||||
RARRAY_ASET(ast->mark_ary, i, Qnil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue