ruby-changes:65439
From: Jean <ko1@a...>
Date: Thu, 11 Mar 2021 06:44:19 +0900 (JST)
Subject: [ruby-changes:65439] 8463c8a425 (master): Specialize ibf_load_object_symbol and ibf_dump_object_symbol
https://git.ruby-lang.org/ruby.git/commit/?id=8463c8a425 From 8463c8a425758fd4dc58a5c202aba295c837b154 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Fri, 22 Jan 2021 22:23:30 +0100 Subject: Specialize ibf_load_object_symbol and ibf_dump_object_symbol --- compile.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/compile.c b/compile.c index ee6897e..898b02e 100644 --- a/compile.c +++ b/compile.c @@ -11632,17 +11632,37 @@ static void https://github.com/ruby/ruby/blob/trunk/compile.c#L11632 ibf_dump_object_symbol(struct ibf_dump *dump, VALUE obj) { VALUE str = rb_sym2str(obj); - VALUE str_index = ibf_dump_object(dump, str); - ibf_dump_write_small_value(dump, str_index); + long encindex = (long)rb_enc_get_index(str); + long len = RSTRING_LEN(str); + const char *ptr = RSTRING_PTR(str); + + if (encindex > RUBY_ENCINDEX_BUILTIN_MAX) { + rb_encoding *enc = rb_enc_from_index((int)encindex); + const char *enc_name = rb_enc_name(enc); + encindex = RUBY_ENCINDEX_BUILTIN_MAX + ibf_dump_object(dump, rb_str_new2(enc_name)); + } + + ibf_dump_write_small_value(dump, encindex); + ibf_dump_write_small_value(dump, len); + IBF_WP(ptr, char, len); } static VALUE ibf_load_object_symbol(const struct ibf_load *load, const struct ibf_object_header *header, ibf_offset_t offset) { - VALUE str_index = ibf_load_small_value(load, &offset); - VALUE str = ibf_load_object(load, str_index); - ID id = rb_intern_str(str); + ibf_offset_t reading_pos = offset; + + int encindex = (int)ibf_load_small_value(load, &reading_pos); + const long len = (long)ibf_load_small_value(load, &reading_pos); + const char *ptr = load->current_buffer->buff + reading_pos; + + if (encindex > RUBY_ENCINDEX_BUILTIN_MAX) { + VALUE enc_name_str = ibf_load_object(load, encindex - RUBY_ENCINDEX_BUILTIN_MAX); + encindex = rb_enc_find_index(RSTRING_PTR(enc_name_str)); + } + + ID id = rb_intern3(ptr, len, rb_enc_from_index(encindex)); return ID2SYM(id); } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/