From 58c1184716ac790a570117bbd497f116274530b9 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Sun, 6 Oct 2019 22:50:38 +0300 Subject: [PATCH] Faster Hash duping in #json_clone (#4314) * Faster Hash duping in #json_clone * Reorder branches for json_clone --- lib/sidekiq/processor.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 158117bb..71467850 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -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