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
|
# 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
|
||||||
|
|
Loading…
Reference in a new issue