summaryrefslogtreecommitdiff
path: root/lib/coderay/helpers
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-06-13 01:07:56 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2016-06-13 01:07:56 +0200
commite01ccf7c5f1da22d2d131a84d36eeebdebe92f1c (patch)
tree0faa2550f16eb8899a1681a11a56dd8c7c5d07ab /lib/coderay/helpers
parent545398fac57b5949359298e1f258e1746adfa3e5 (diff)
parentc999deb1e932b3290561a58923603eb87809c8df (diff)
downloadcoderay-e01ccf7c5f1da22d2d131a84d36eeebdebe92f1c.tar.gz
Merge branch 'possible-speedups' into dsl
Diffstat (limited to 'lib/coderay/helpers')
-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 []