diff options
author | Jean Boussier <[email protected]> | 2024-04-10 10:50:18 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2024-04-11 09:04:31 +0200 |
commit | 1b830740ba8371c4bcfdfc6eb2cb7e0ae81a84e0 (patch) | |
tree | 7f4b1c983035adaaa52bf966e54f1f4738098d4c /ruby_parser.c | |
parent | ed303cd56cfc7889ce371ee390e9fd36f86814ea (diff) |
compile.c: use rb_enc_interned_str to reduce allocations
The `rb_fstring(rb_enc_str_new())` pattern is inneficient because:
- It passes a mutable string to `rb_fstring` so if it has to be interned
it will first be duped.
- It an equivalent interned string already exists, we allocated the string
for nothing.
With `rb_enc_interned_str` we either directly get the pre-existing string
with 0 allocations, or efficiently directly intern the one we create
without first duping it.
Diffstat (limited to 'ruby_parser.c')
-rw-r--r-- | ruby_parser.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ruby_parser.c b/ruby_parser.c index 12bfb18b1a..40c469f14b 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -742,6 +742,14 @@ rb_parser_set_yydebug(VALUE vparser, VALUE flag) VALUE rb_str_new_parser_string(rb_parser_string_t *str) { + VALUE string = rb_enc_interned_str(str->ptr, str->len, str->enc); + rb_enc_str_coderange(string); + return string; +} + +VALUE +rb_str_new_mutable_parser_string(rb_parser_string_t *str) +{ return rb_enc_str_new(str->ptr, str->len, str->enc); } |