From: Giuseppe Bilotta Date: Sun, 2 Sep 2007 09:30:13 +0000 (+0000) Subject: plugins.rb: use fast delegation hash X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=b835c480b45f41dc59756bbaeed7c92aa14de9f9;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git 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). --- 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