diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2016-06-13 01:02:48 +0200 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2016-06-13 01:02:48 +0200 |
commit | 122dd5feef0e61ae10879f11e0fd40fdac7c3d26 (patch) | |
tree | dd51975d4bf752527c0d92854290e6594cf9b345 /lib | |
parent | aa9229ff97a7d7252c52cf1df5bc076871f4b197 (diff) | |
download | coderay-122dd5feef0e61ae10879f11e0fd40fdac7c3d26.tar.gz |
speedup plugin lookup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/coderay/helpers/plugin_host.rb | 20 |
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 [] |