1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #40033 from dpep/deep-dup

deep dup optimization
This commit is contained in:
Rafael França 2020-08-25 20:25:09 -04:00 committed by GitHub
commit ee6ee11b01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -43,7 +43,7 @@ class Hash
def deep_dup
hash = dup
each_pair do |key, value|
if key.frozen? && ::String === key
if (::String === key && key.frozen?) || ::Symbol === key
hash[key] = value.deep_dup
else
hash.delete(key)

View file

@ -56,4 +56,14 @@ class DeepDupTest < ActiveSupport::TestCase
dup = hash.deep_dup
assert_equal 1, dup.keys.length
end
def test_deep_dup_with_mutable_frozen_key
key = { array: [] }.freeze
hash = { key => :value }
dup = hash.deep_dup
dup.transform_keys { |k| k[:array] << :array_element }
assert_not_equal hash.keys, dup.keys
end
end