summaryrefslogtreecommitdiff
path: root/lib/irb/context.rb
diff options
context:
space:
mode:
authorStan Lo <[email protected]>2024-11-20 18:59:23 +0000
committergit <[email protected]>2024-11-20 18:59:26 +0000
commit51bf0d4d68fb6cc2b073ab45ce882ab5bbece629 (patch)
treeaf06fe76b464c19e69506e6e8689c5e966304f16 /lib/irb/context.rb
parent2bf5d26eb9eac56cef326d470fb7bd50261df7fe (diff)
[ruby/irb] Store method objects in constants
(https://github.com/ruby/irb/pull/1033) It probably won't speed up things significantly, but these are hot paths and we can save a few method calls per completion/input call. https://github.com/ruby/irb/commit/f1e25ec7ae
Diffstat (limited to 'lib/irb/context.rb')
-rw-r--r--lib/irb/context.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index bcbbb8b82e..c656281922 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -13,6 +13,9 @@ module IRB
# A class that wraps the current state of the irb session, including the
# configuration of IRB.conf.
class Context
+ KERNEL_PUBLIC_METHOD = ::Kernel.instance_method(:public_method)
+ KERNEL_METHOD = ::Kernel.instance_method(:method)
+
ASSIGN_OPERATORS_REGEXP = Regexp.union(%w[= += -= *= /= %= **= &= |= &&= ||= ^= <<= >>=])
# Creates a new IRB context.
#
@@ -648,8 +651,8 @@ module IRB
return if local_variables.include?(command)
# Check visibility
- public_method = !!Kernel.instance_method(:public_method).bind_call(main, command) rescue false
- private_method = !public_method && !!Kernel.instance_method(:method).bind_call(main, command) rescue false
+ public_method = !!KERNEL_PUBLIC_METHOD.bind_call(main, command) rescue false
+ private_method = !public_method && !!KERNEL_METHOD.bind_call(main, command) rescue false
if Command.execute_as_command?(command, public_method: public_method, private_method: private_method)
[command, arg]
end