diff options
author | Jean Boussier <[email protected]> | 2023-11-02 11:02:43 +0100 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2023-11-02 23:34:58 +0100 |
commit | ac8ec004e5272d589caca30616dbe12862150188 () | |
tree | a3fb421e8ad6ddf400130b81fe33805c7c352fab | |
parent | ee7bf4643d2716d44e13a732caf588b1a6275f7a (diff) |
Make String.new size pools aware.
If the required capacity would fit in an embded string, returns one. This can reduce malloc churn for code that use string buffers.
-rw-r--r-- | string.c | 93 | ||||
-rw-r--r-- | test/-ext-/string/test_capacity.rb | 2 |
2 files changed, 94 insertions, 1 deletions
@@ -1874,6 +1874,98 @@ rb_str_init(int argc, VALUE *argv, VALUE str) return str; } #ifdef NONASCII_MASK #define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80) @@ -11931,6 +12023,7 @@ Init_String(void) st_foreach(rb_vm_fstring_table(), fstring_set_class_i, rb_cString); rb_include_module(rb_cString, rb_mComparable); rb_define_alloc_func(rb_cString, empty_str_alloc); rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1); rb_define_method(rb_cString, "initialize", rb_str_init, -1); rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1); @@ -23,7 +23,7 @@ class Test_StringCapacity < Test::Unit::TestCase def test_s_new_capacity assert_equal("", String.new(capacity: 1000)) assert_equal(String, String.new(capacity: 1000).class) - assert_equal(10000, capa(String.new(capacity: 10000))) assert_equal("", String.new(capacity: -1000)) assert_equal(capa(String.new(capacity: -10000)), capa(String.new(capacity: -1000))) |