summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-06-13 01:02:48 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2016-06-13 01:02:48 +0200
commit122dd5feef0e61ae10879f11e0fd40fdac7c3d26 (patch)
treedd51975d4bf752527c0d92854290e6594cf9b345
parentaa9229ff97a7d7252c52cf1df5bc076871f4b197 (diff)
downloadcoderay-122dd5feef0e61ae10879f11e0fd40fdac7c3d26.tar.gz
speedup plugin lookup
-rw-r--r--lib/coderay/helpers/plugin_host.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/coderay/helpers/plugin_host.rb b/lib/coderay/helpers/plugin_host.rb
index e9bc17c..12ee29d 100644
--- a/lib/coderay/helpers/plugin_host.rb
+++ b/lib/coderay/helpers/plugin_host.rb
@@ -47,11 +47,21 @@ module CodeRay
# Example:
# yaml_plugin = MyPluginHost[:yaml]
def [] id, *args, &blk
- plugin = validate_id(id)
- begin
- plugin = plugin_hash.[](plugin, *args, &blk)
- end while plugin.is_a? String
- plugin
+ if !args.empty? || blk
+ plugin = validate_id(id)
+ begin
+ plugin = plugin_hash.[](plugin, *args, &blk)
+ end while plugin.is_a? String
+ plugin
+ else
+ (@cache ||= Hash.new do |cache, key|
+ plugin = validate_id(key)
+ begin
+ plugin = plugin_hash.[](plugin)
+ end while plugin.is_a? String
+ cache[key] = plugin
+ end)[id]
+ end
end
alias load []