summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-07-21 20:58:07 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-07-21 20:58:07 +0200
commitee992427810a1cf88b53c12ccf7fda91a30ab33e (patch)
tree458368175989f5c6c938e00bfa46e72894ddf2ad /lib
parent05f5a0e270ce2cde4ff242634033c902c58f13ea (diff)
downloadcoderay-ee992427810a1cf88b53c12ccf7fda91a30ab33e.tar.gz
limit HTML encoder span_for_kinds cache sizev1.1.0.rc3
Diffstat (limited to 'lib')
-rw-r--r--lib/coderay/encoders/html.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 81a6ffa..ffde5d2 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -284,9 +284,8 @@ module Encoders
end
def make_span_for_kinds method, hint
- # FIXME: cache attack
Hash.new do |h, kinds|
- h[kinds] = begin
+ begin
css_class = css_class_for_kinds(kinds)
title = HTML.token_path_to_hint hint, kinds if hint
@@ -298,6 +297,9 @@ module Encoders
"<span#{title}#{" class=\"#{css_class}\"" if css_class}>"
end
end
+ end.tap do |span|
+ h.clear if h.size >= 100
+ h[kinds] = span
end
end
end