Skip to content

Commit 122dd5f

Browse files
committed
speedup plugin lookup
1 parent aa9229f commit 122dd5f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/coderay/helpers/plugin_host.rb

+15-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ def load_all
4747
# Example:
4848
# yaml_plugin = MyPluginHost[:yaml]
4949
def [] id, *args, &blk
50-
plugin = validate_id(id)
51-
begin
52-
plugin = plugin_hash.[](plugin, *args, &blk)
53-
end while plugin.is_a? String
54-
plugin
50+
if !args.empty? || blk
51+
plugin = validate_id(id)
52+
begin
53+
plugin = plugin_hash.[](plugin, *args, &blk)
54+
end while plugin.is_a? String
55+
plugin
56+
else
57+
(@cache ||= Hash.new do |cache, key|
58+
plugin = validate_id(key)
59+
begin
60+
plugin = plugin_hash.[](plugin)
61+
end while plugin.is_a? String
62+
cache[key] = plugin
63+
end)[id]
64+
end
5565
end
5666

5767
alias load []

0 commit comments

Comments
 (0)