summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2024-04-10 10:50:18 +0200
committerJean Boussier <jean.boussier@gmail.com>2024-04-11 09:04:31 +0200
commit1b830740ba8371c4bcfdfc6eb2cb7e0ae81a84e0 (patch)
tree7f4b1c983035adaaa52bf966e54f1f4738098d4c /test/ruby
parented303cd56cfc7889ce371ee390e9fd36f86814ea (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 'test/ruby')
-rw-r--r--test/ruby/test_shapes.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index bbea03344e..9b02504384 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -1006,7 +1006,7 @@ class TestShapes < Test::Unit::TestCase
end
def test_freezing_and_cloning_string
- str = "str".freeze
+ str = ("str" + "str").freeze
str2 = str.clone(freeze: true)
assert_predicate(str2, :frozen?)
assert_shape_equal(RubyVM::Shape.of(str), RubyVM::Shape.of(str2))