diff options
-rw-r--r-- | string.c | 17 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 21 |
2 files changed, 25 insertions, 13 deletions
@@ -3340,28 +3340,19 @@ rb_str_append(VALUE str, VALUE str2) return rb_str_buf_append(str, str2); } -#define MIN_PRE_ALLOC_SIZE 48 - MJIT_FUNC_EXPORTED VALUE rb_str_concat_literals(size_t num, const VALUE *strary) { VALUE str; - size_t i, s; - long len = 1; + size_t i, s = 0; + unsigned long len = 1; if (UNLIKELY(!num)) return rb_str_new(0, 0); if (UNLIKELY(num == 1)) return rb_str_resurrect(strary[0]); for (i = 0; i < num; ++i) { len += RSTRING_LEN(strary[i]); } - if (LIKELY(len < MIN_PRE_ALLOC_SIZE)) { - str = rb_str_resurrect(strary[0]); - s = 1; - } - else { - str = rb_str_buf_new(len); - rb_enc_copy(str, strary[0]); - s = 0; - } + str = rb_str_buf_new(len); + str_enc_copy(str, strary[0]); for (i = s; i < num; ++i) { const VALUE v = strary[i]; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 1ece47b18a..e34fd116c9 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -661,6 +661,27 @@ CODE assert_equal(Encoding::UTF_8, "#{s}x".encoding) end + def test_string_interpolations_across_size_pools_get_embedded + omit if GC::INTERNAL_CONSTANTS[:SIZE_POOL_COUNT] == 1 + + require 'objspace' + base_slot_size = GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + small_obj_size = (base_slot_size / 2) + large_obj_size = base_slot_size * 2 + + a = "a" * small_obj_size + b = "a" * large_obj_size + + res = "#{a}, #{b}" + dump_res = ObjectSpace.dump(res) + dump_orig = ObjectSpace.dump(a) + new_slot_size = Integer(dump_res.match(/"slot_size":(\d+)/)[1]) + orig_slot_size = Integer(dump_orig.match(/"slot_size":(\d+)/)[1]) + + assert_match(/"embedded":true/, dump_res) + assert_operator(new_slot_size, :>, orig_slot_size) + end + def test_count a = S("hello world") assert_equal(5, a.count(S("lo"))) |