diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-02 09:30:13 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-02 09:30:13 +0000 |
commit | b835c480b45f41dc59756bbaeed7c92aa14de9f9 (patch) | |
tree | 24e448251c43e009fecbb058404f4bdbc8beb677 /lib/rbot | |
parent | 1ef981bb3b47c396b5b0c99698dcf7063c83d4ff (diff) |
plugins.rb: use fast delegation hash
We delegate common hooks through the fast-delegation hash, and revert to
brute-force querying for everything else. Beware that this may breaks plugins
which add/remove delegatable methods at runtime, but no such plugin is
currently used (AFAIK).
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/plugins.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 9880d720..7bec55ae 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -646,18 +646,35 @@ module Plugins def delegate(method, *args) # debug "Delegating #{method.inspect}" ret = Array.new - (core_modules + plugins).each { |p| - if(p.respond_to? method) + if method.match(DEFAULT_DELEGATE_PATTERNS) + debug "fast-delegating #{method}" + m = method.to_sym + debug "no-one to delegate to" unless @delegate_list.has_key?(m) + return [] unless @delegate_list.has_key?(m) + @delegate_list[m].each { |p| begin - # debug "#{p.botmodule_class} #{p.name} responds" ret.push p.send(method, *args) rescue Exception => err raise if err.kind_of?(SystemExit) error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err) raise if err.kind_of?(BDB::Fatal) end - end - } + } + else + debug "slow-delegating #{method}" + (core_modules + plugins).each { |p| + if(p.respond_to? method) + begin + # debug "#{p.botmodule_class} #{p.name} responds" + ret.push p.send(method, *args) + rescue Exception => err + raise if err.kind_of?(SystemExit) + error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err) + raise if err.kind_of?(BDB::Fatal) + end + end + } + end return ret # debug "Finished delegating #{method.inspect}" end |