diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-06 15:41:21 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-07 08:28:36 +0900 |
commit | 344ec26a99e09c2d2f756fa6384e75ffa48f415f (patch) | |
tree | 71aeb66c03bad047e36de3b7a5ab74962139f789 /string.c | |
parent | 59ddb88da6bf483eeec7b85b8a85cf3719edf440 (diff) |
tuning trial: newobj with current ec
Passing current ec can improve performance of newobj. This patch
tries it for Array and String literals ([] and '').
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3842
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -1543,7 +1543,14 @@ str_replace(VALUE str, VALUE str2) } static inline VALUE -str_duplicate(VALUE klass, VALUE str) +ec_str_alloc(struct rb_execution_context_struct *ec, VALUE klass) +{ + RB_EC_NEWOBJ_OF(ec, str, struct RString, klass, T_STRING | (RGENGC_WB_PROTECTED_STRING ? FL_WB_PROTECTED : 0)); + return (VALUE)str; +} + +static inline VALUE +str_duplicate_setup(VALUE klass, VALUE str, VALUE dup) { enum {embed_size = RSTRING_EMBED_LEN_MAX + 1}; const VALUE flag_mask = @@ -1552,7 +1559,6 @@ str_duplicate(VALUE klass, VALUE str) FL_FREEZE ; VALUE flags = FL_TEST_RAW(str, flag_mask); - VALUE dup = str_alloc(klass); int encidx = 0; MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary, char, embed_size); @@ -1582,6 +1588,20 @@ str_duplicate(VALUE klass, VALUE str) return dup; } +static inline VALUE +ec_str_duplicate(struct rb_execution_context_struct *ec, VALUE klass, VALUE str) +{ + VALUE dup = ec_str_alloc(ec, klass); + return str_duplicate_setup(klass, str, dup); +} + +static inline VALUE +str_duplicate(VALUE klass, VALUE str) +{ + VALUE dup = str_alloc(klass); + return str_duplicate_setup(klass, str, dup); +} + VALUE rb_str_dup(VALUE str) { @@ -1595,6 +1615,13 @@ rb_str_resurrect(VALUE str) return str_duplicate(rb_cString, str); } +VALUE +rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str) +{ + RUBY_DTRACE_CREATE_HOOK(STRING, RSTRING_LEN(str)); + return ec_str_duplicate(ec, rb_cString, str); +} + /* * call-seq: * String.new(string = '') -> new_string |