1
0
Fork 0
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:
fatkodima 2019-10-06 22:50:38 +03:00 committed by Mike Perham
parent 3380c12af9
commit 58c1184716

View file

@ -278,15 +278,15 @@ module Sidekiq
# the job fails, what is pushed back onto Redis hasn't # the job fails, what is pushed back onto Redis hasn't
# been mutated by the worker. # been mutated by the worker.
def json_clone(obj) def json_clone(obj)
if Integer === obj || Float === obj || TrueClass === obj || FalseClass === obj || NilClass === obj if String === obj
obj
elsif String === obj
obj.dup obj.dup
elsif Integer === obj || Float === obj || TrueClass === obj || FalseClass === obj || NilClass === obj
obj
elsif Array === obj elsif Array === obj
obj.map { |e| json_clone(e) } obj.map { |e| json_clone(e) }
elsif Hash === obj elsif Hash === obj
duped = obj.dup duped = {}
duped.each_pair do |key, value| obj.each_pair do |key, value|
duped[key] = json_clone(value) duped[key] = json_clone(value)
end end
duped duped