ruby-changes:58162
From: Nobuyoshi <ko1@a...>
Date: Tue, 8 Oct 2019 17:29:33 +0900 (JST)
Subject: [ruby-changes:58162] 8feb8c9bb7 (master): Packed delayed token elements
https://git.ruby-lang.org/ruby.git/commit/?id=8feb8c9bb7 From 8feb8c9bb7e9036ee2014b0f532677635a16893e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 8 Oct 2019 09:13:58 +0900 Subject: Packed delayed token elements diff --git a/parse.y b/parse.y index 287704e..2fd01dd 100644 --- a/parse.y +++ b/parse.y @@ -302,9 +302,11 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L302 #else /* Ripper only */ - VALUE delayed; - int delayed_line; - int delayed_col; + struct { + VALUE token; + int line; + int col; + } delayed; VALUE value; VALUE result; @@ -5432,16 +5434,16 @@ ripper_dispatch_delayed_token(struct parser_params *p, enum yytokentype t) https://github.com/ruby/ruby/blob/trunk/parse.y#L5434 int saved_line = p->ruby_sourceline; const char *saved_tokp = p->lex.ptok; - if (NIL_P(p->delayed)) return; - p->ruby_sourceline = p->delayed_line; - p->lex.ptok = p->lex.pbeg + p->delayed_col; - add_mark_object(p, yylval_rval = ripper_dispatch1(p, ripper_token2eventid(t), p->delayed)); - p->delayed = Qnil; + if (NIL_P(p->delayed.token)) return; + p->ruby_sourceline = p->delayed.line; + p->lex.ptok = p->lex.pbeg + p->delayed.col; + add_mark_object(p, yylval_rval = ripper_dispatch1(p, ripper_token2eventid(t), p->delayed.token)); + p->delayed.token = Qnil; p->ruby_sourceline = saved_line; p->lex.ptok = saved_tokp; } #define dispatch_delayed_token(p, t) ripper_dispatch_delayed_token(p, t) -#define has_delayed_token(p) (!NIL_P(p->delayed)) +#define has_delayed_token(p) (!NIL_P(p->delayed.token)) #endif /* RIPPER */ #include "ruby/regex.h" @@ -6110,12 +6112,12 @@ add_delayed_token(struct parser_params *p, const char *tok, const char *end) https://github.com/ruby/ruby/blob/trunk/parse.y#L6112 { if (tok < end) { if (!has_delayed_token(p)) { - p->delayed = rb_str_buf_new(1024); - rb_enc_associate(p->delayed, p->enc); - p->delayed_line = p->ruby_sourceline; - p->delayed_col = (int)(tok - p->lex.pbeg); + p->delayed.token = rb_str_buf_new(end - tok); + rb_enc_associate(p->delayed.token, p->enc); + p->delayed.line = p->ruby_sourceline; + p->delayed.col = rb_long2int(tok - p->lex.pbeg); } - rb_str_buf_cat(p->delayed, tok, end - tok); + rb_str_buf_cat(p->delayed.token, tok, end - tok); p->lex.ptok = end; } } @@ -6861,7 +6863,7 @@ flush_string_content(struct parser_params *p, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/parse.y#L6863 if (has_delayed_token(p)) { ptrdiff_t len = p->lex.pcur - p->lex.ptok; if (len > 0) { - rb_enc_str_buf_cat(p->delayed, p->lex.ptok, len, enc); + rb_enc_str_buf_cat(p->delayed.token, p->lex.ptok, len, enc); } dispatch_delayed_token(p, tSTRING_CONTENT); p->lex.ptok = p->lex.pcur; @@ -7389,7 +7391,7 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here) https://github.com/ruby/ruby/blob/trunk/parse.y#L7391 enc = rb_ascii8bit_encoding(); } } - rb_enc_str_buf_cat(p->delayed, p->lex.ptok, len, enc); + rb_enc_str_buf_cat(p->delayed.token, p->lex.ptok, len, enc); } dispatch_delayed_token(p, tSTRING_CONTENT); } @@ -12183,7 +12185,7 @@ parser_initialize(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L12185 p->lex.lpar_beg = -1; /* make lambda_beginning_p() == FALSE at first */ p->node_id = 0; #ifdef RIPPER - p->delayed = Qnil; + p->delayed.token = Qnil; p->result = Qnil; p->parsing_thread = Qnil; #else @@ -12217,7 +12219,7 @@ parser_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/parse.y#L12219 rb_gc_mark(p->compile_option); rb_gc_mark(p->error_buffer); #else - rb_gc_mark(p->delayed); + rb_gc_mark(p->delayed.token); rb_gc_mark(p->value); rb_gc_mark(p->result); rb_gc_mark(p->parsing_thread); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/