mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 07:26:00 +02:00
register_fstring: avoid duping the passed string when possible
If the passed string is frozen, bare and not shared, then there
is no need to duplicate it.
Ref: 4ab69ebbd7
Ref: https://bugs.ruby-lang.org/issues/11386
This commit is contained in:
parent
7f0ea20581
commit
aaf0e33c0a
Notes:
git
2020-08-20 00:09:32 +09:00
2 changed files with 18 additions and 1 deletions
|
@ -3187,6 +3187,22 @@ CODE
|
|||
assert_same(str, -bar, "uminus deduplicates [Feature #13077]")
|
||||
end
|
||||
|
||||
def test_uminus_frozen
|
||||
# embedded
|
||||
str1 = ("foobar" * 3).freeze
|
||||
str2 = ("foobar" * 3).freeze
|
||||
assert_not_same str1, str2
|
||||
assert_same str1, -str1
|
||||
assert_same str1, -str2
|
||||
|
||||
# regular
|
||||
str1 = ("foobar" * 4).freeze
|
||||
str2 = ("foobar" * 4).freeze
|
||||
assert_not_same str1, str2
|
||||
assert_same str1, -str1
|
||||
assert_same str1, -str2
|
||||
end
|
||||
|
||||
def test_uminus_no_freeze_not_bare
|
||||
str = @cls.new("foo")
|
||||
assert_instance_of(@cls, -str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue