Skip to content

Commit 52d9e55

Browse files
committed
Statically allocate parser config
1 parent c3b2436 commit 52d9e55

File tree

7 files changed

+244
-269
lines changed

7 files changed

+244
-269
lines changed

ext/ripper/ripper_init.c.tmpl

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ ripper_s_allocate(VALUE klass)
115115
&parser_data_type, r);
116116

117117
#ifdef UNIVERSAL_PARSER
118-
rb_parser_config_t *config;
119-
config = rb_ruby_parser_config_new(ruby_xmalloc);
120-
rb_parser_config_initialize(config);
121-
r->p = rb_ruby_parser_allocate(config);
118+
r->p = rb_parser_params_allocate();
122119
#else
123120
r->p = rb_ruby_ripper_parser_allocate();
124121
#endif
@@ -260,11 +257,11 @@ parser_dedent_string0(VALUE a)
260257
}
261258

262259
static VALUE
263-
parser_config_free(VALUE a)
260+
parser_free(VALUE a)
264261
{
265-
rb_parser_config_t *config = (void *)a;
262+
struct parser_params *p = (void *)a;
266263

267-
rb_ruby_parser_config_free(config);
264+
rb_ruby_parser_free(p);
268265
return Qnil;
269266
}
270267
#endif
@@ -283,17 +280,14 @@ static VALUE
283280
parser_dedent_string(VALUE self, VALUE input, VALUE width)
284281
{
285282
struct parser_params *p;
286-
rb_parser_config_t *config;
287283
struct dedent_string_arg args;
288284

289-
config = rb_ruby_parser_config_new(ruby_xmalloc);
290-
rb_parser_config_initialize(config);
291-
p = rb_ruby_parser_new(config);
285+
p = rb_parser_params_new();
292286

293287
args.p = p;
294288
args.input = input;
295289
args.width = width;
296-
return rb_ensure(parser_dedent_string0, (VALUE)&args, parser_config_free, (VALUE)config);
290+
return rb_ensure(parser_dedent_string0, (VALUE)&args, parser_free, (VALUE)p);
297291
}
298292
#else
299293
static VALUE
@@ -530,17 +524,14 @@ static VALUE
530524
ripper_lex_state_name(VALUE self, VALUE state)
531525
{
532526
struct parser_params *p;
533-
rb_parser_config_t *config;
534527
struct lex_state_name_arg args;
535528

536-
config = rb_ruby_parser_config_new(ruby_xmalloc);
537-
rb_parser_config_initialize(config);
538-
p = rb_ruby_parser_new(config);
529+
p = rb_parser_params_new();
539530

540531
args.p = p;
541532
args.state = state;
542533

543-
return rb_ensure(lex_state_name0, (VALUE)&args, parser_config_free, (VALUE)config);
534+
return rb_ensure(lex_state_name0, (VALUE)&args, parser_free, (VALUE)p);
544535
}
545536
#else
546537
static VALUE

internal/ruby_parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
RUBY_SYMBOL_EXPORT_BEGIN
1414
#ifdef UNIVERSAL_PARSER
15-
void rb_parser_config_initialize(rb_parser_config_t *config);
15+
rb_parser_t *rb_parser_params_allocate(void);
16+
rb_parser_t *rb_parser_params_new(void);
1617
#endif
1718
VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int);
1819
VALUE rb_parser_new(void);

node.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,18 +426,8 @@ void
426426
rb_ast_free(rb_ast_t *ast)
427427
{
428428
if (ast->node_buffer) {
429-
#ifdef UNIVERSAL_PARSER
430-
rb_parser_config_t *config = ast->node_buffer->config;
431-
#endif
432-
433429
rb_node_buffer_free(ast, ast->node_buffer);
434430
ast->node_buffer = 0;
435-
#ifdef UNIVERSAL_PARSER
436-
config->counter--;
437-
if (config->counter <= 0) {
438-
rb_ruby_parser_config_free(config);
439-
}
440-
#endif
441431
}
442432
}
443433

parse.y

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15905,9 +15905,6 @@ rb_ruby_parser_free(void *ptr)
1590515905
{
1590615906
struct parser_params *p = (struct parser_params*)ptr;
1590715907
struct local_vars *local, *prev;
15908-
#ifdef UNIVERSAL_PARSER
15909-
rb_parser_config_t *config = p->config;
15910-
#endif
1591115908

1591215909
if (p->tokenbuf) {
1591315910
ruby_sized_xfree(p->tokenbuf, p->toksiz);
@@ -15926,13 +15923,6 @@ rb_ruby_parser_free(void *ptr)
1592615923
}
1592715924
}
1592815925
xfree(ptr);
15929-
15930-
#ifdef UNIVERSAL_PARSER
15931-
config->counter--;
15932-
if (config->counter <= 0) {
15933-
rb_ruby_parser_config_free(config);
15934-
}
15935-
#endif
1593615926
}
1593715927

1593815928
size_t
@@ -15950,20 +15940,6 @@ rb_ruby_parser_memsize(const void *ptr)
1595015940
return size;
1595115941
}
1595215942

15953-
#ifdef UNIVERSAL_PARSER
15954-
rb_parser_config_t *
15955-
rb_ruby_parser_config_new(void *(*malloc)(size_t size))
15956-
{
15957-
return (rb_parser_config_t *)malloc(sizeof(rb_parser_config_t));
15958-
}
15959-
15960-
void
15961-
rb_ruby_parser_config_free(rb_parser_config_t *config)
15962-
{
15963-
config->free(config);
15964-
}
15965-
#endif
15966-
1596715943
#ifndef UNIVERSAL_PARSER
1596815944
#ifndef RIPPER
1596915945
static const rb_data_type_t parser_data_type = {

0 commit comments

Comments
 (0)