Skip to content

Commit

Permalink
Switch back to Hash.dup
Browse files Browse the repository at this point in the history
The performance difference between `Hash[]` and `Hash.dup` looks to have
been narrowed by @tenderlove via this commit --> ruby/ruby@b3803cc#diff-eff9999082c8ce7d8ba1fc1d79f439cf.
Since this commit first appeared in Ruby 2.0.0, and since Rails now
requires a minimum Ruby version of 2.2.2, this performance boost should
be available for all users.

Relevant links:

- This behavior was originally added via rails@02174a3
- The conversation on the Ruby issue tracker lives here --> https://bugs.ruby-lang.org/issues/7166
  • Loading branch information
maclover7 committed Aug 27, 2016
1 parent a63de6d commit 79a2d07
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def initialize(klass, table, predicate_builder, values = {})
end

def initialize_copy(other)
# This method is a hot spot, so for now, use Hash[] to dup the hash.
# https://bugs.ruby-lang.org/issues/7166
@values = Hash[@values]
@values = @values.dup
reset
end

Expand Down Expand Up @@ -661,7 +659,7 @@ def blank?
end

def values
Hash[@values]
@values.dup
end

def inspect
Expand Down

0 comments on commit 79a2d07

Please sign in to comment.