mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Faster Hash duping in #json_clone (#4314)
* Faster Hash duping in #json_clone * Reorder branches for json_clone
This commit is contained in:
parent
3380c12af9
commit
58c1184716
1 changed files with 5 additions and 5 deletions
|
@ -278,15 +278,15 @@ module Sidekiq
|
|||
# the job fails, what is pushed back onto Redis hasn't
|
||||
# been mutated by the worker.
|
||||
def json_clone(obj)
|
||||
if Integer === obj || Float === obj || TrueClass === obj || FalseClass === obj || NilClass === obj
|
||||
obj
|
||||
elsif String === obj
|
||||
if String === obj
|
||||
obj.dup
|
||||
elsif Integer === obj || Float === obj || TrueClass === obj || FalseClass === obj || NilClass === obj
|
||||
obj
|
||||
elsif Array === obj
|
||||
obj.map { |e| json_clone(e) }
|
||||
elsif Hash === obj
|
||||
duped = obj.dup
|
||||
duped.each_pair do |key, value|
|
||||
duped = {}
|
||||
obj.each_pair do |key, value|
|
||||
duped[key] = json_clone(value)
|
||||
end
|
||||
duped
|
||||
|
|
Loading…
Reference in a new issue