[ruby/timeout] Avoid unnecessary object allocation

Idea from nobu.

https://github.com/ruby/timeout/commit/aecdaa23b3
This commit is contained in:
Jeremy Evans 2021-05-03 08:31:59 -07:00 committed by Hiroshi SHIBATA
parent 33b5e179a8
commit 44e8575ca6

View File

@ -32,9 +32,8 @@ module Timeout
def self.catch(*args)
exc = new(*args)
exc.instance_variable_set(:@thread, Thread.current)
catch_value = Object.new
exc.instance_variable_set(:@catch_value, catch_value)
::Kernel.catch(catch_value) {yield exc}
exc.instance_variable_set(:@catch_value, exc)
::Kernel.catch(exc) {yield exc}
end
def exception(*)