From a6b1cf368b1d6ab8b66a69eb63560a898b224d7e Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 2 Sep 2007 09:30:08 +0000 Subject: plugins.rb: set up fast delegation hash Delegating a message requires checking if each of the loaded plugins responds to a given method. This can be time consuming when many plugins are loaded. We set up a hash that maps each commonly delegated method to the list of plugins that respond to it. --- lib/rbot/plugins.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/rbot') diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index e1cf9c9f..9880d720 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -270,6 +270,16 @@ module Plugins attr_reader :bot attr_reader :botmodules + # This is the list of patterns commonly delegated to plugins. + # A fast delegation lookup is enabled for them. + DEFAULT_DELEGATE_PATTERNS = %r{^(?: + connect|names|nick| + listen|ctcp_listen|privmsg|unreplied| + kick|join|part|quit| + save|cleanup|flush_registry| + set_.*|event_.* + )$}x + def initialize @botmodules = { :CoreBotModule => [], @@ -278,6 +288,9 @@ module Plugins @names_hash = Hash.new @commandmappers = Hash.new + @delegate_list = Hash.new { |h, k| + h[k] = Array.new + } @dirs = [] @@ -416,6 +429,8 @@ module Plugins def scan @failed.clear @ignored.clear + @delegate_list.clear + processed = Hash.new @bot.config['plugins.blacklist'].each { |p| @@ -460,6 +475,11 @@ module Plugins end } debug "finished loading plugins: #{status(true)}" + (core_modules + plugins).each { |p| + p.methods.grep(DEFAULT_DELEGATE_PATTERNS).each { |m| + @delegate_list[m.intern] << p + } + } end # call the save method for each active plugin -- cgit v1.2.3