diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-05-03 08:31:59 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-05-06 16:50:31 +0900 |
commit | 44e8575ca6e7749b296366f8e7d8094e4cfd2196 (patch) | |
tree | 03d20a3b8c29e65a033a899f4fa43f0b25c203a7 | |
parent | 33b5e179a88e67f1ee12e2e8993121b2f445b54f (diff) |
[ruby/timeout] Avoid unnecessary object allocation
Idea from nobu.
https://github.com/ruby/timeout/commit/aecdaa23b3
-rw-r--r-- | lib/timeout.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb index 572e90cafb..ee24349a3e 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -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(*) |