Skip to content

Commit c66eb36

Browse files
authored
Avoid a hash object allocation per each query/execute call (#1112)
This is a same optimization approach with ruby/ruby#2393.
1 parent cb9e941 commit c66eb36

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

lib/mysql2.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ def self.key_hash_as_symbols(hash)
8282
else
8383
::Timeout::Error
8484
end
85+
TIMEOUT_ERROR_NEVER = { TIMEOUT_ERROR_CLASS => :never }.freeze
8586
end
8687
end

lib/mysql2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def parse_connect_attrs(conn_attrs)
127127
end
128128

129129
def query(sql, options = {})
130-
Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
130+
Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_NEVER) do
131131
_query(sql, @query_options.merge(options))
132132
end
133133
end

lib/mysql2/statement.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Mysql2
22
class Statement
33
def execute(*args, **kwargs)
4-
Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
4+
Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_NEVER) do
55
_execute(*args, **kwargs)
66
end
77
end

0 commit comments

Comments
 (0)