Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Immutablize#convert_value] reduce number of class comparisons #14234

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/chef/node/immutable_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ def safe_dup(e)
end

def convert_value(value)
# The order in this case statement is *important*.
# ImmutableMash and ImmutableArray should be tested first,
# as this saves unnecessary creation of intermediate objects
case value
when ImmutableMash, ImmutableArray
value
when Hash
ImmutableMash.new(value, __root__, __node__, __precedence__)
if ImmutableMash === value
tpowell-progress marked this conversation as resolved.
Show resolved Hide resolved
# Save an object creation
value
else
ImmutableMash.new(value, __root__, __node__, __precedence__)
end
when Array
ImmutableArray.new(value, __root__, __node__, __precedence__)
if ImmutableArray === value
# Save an object creation
value
else
ImmutableArray.new(value, __root__, __node__, __precedence__)
end
else
safe_dup(value).freeze
end
Expand Down