Skip to content

Commit

Permalink
Avoid unnecessary object allocation
Browse files Browse the repository at this point in the history
Idea from nobu.
  • Loading branch information
jeremyevans committed May 3, 2021
1 parent 952154d commit aecdaa2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class Error < RuntimeError
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(*)
Expand Down

0 comments on commit aecdaa2

Please sign in to comment.