summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2009-12-30 07:08:12 +0000
committermurphy <murphy@rubychan.de>2009-12-30 07:08:12 +0000
commit7550bba0a46f791bf4e052617542a33250ca5cd3 (patch)
treef2241c580638ab4cf0d19451b5b21dce1acea0d4 /lib/coderay
parent5be0927a5dfecd56c45b4f4c3a5a19d5e1ac9729 (diff)
downloadcoderay-7550bba0a46f791bf4e052617542a33250ca5cd3.tar.gz
Documentation: Added warning about WordList caching.
Diffstat (limited to 'lib/coderay')
-rw-r--r--lib/coderay/helpers/word_list.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/coderay/helpers/word_list.rb b/lib/coderay/helpers/word_list.rb
index c8cc7ac..9b4f456 100644
--- a/lib/coderay/helpers/word_list.rb
+++ b/lib/coderay/helpers/word_list.rb
@@ -98,6 +98,8 @@ class CaseIgnoringWordList < WordList
# Creates a new case-insensitive WordList with +default+ as default value.
#
# You can activate caching to store the results for every [] request.
+ # This speeds up subsequent lookups for the same word, but also
+ # uses memory.
def initialize default = false, caching = false
if caching
super(default, false) do |h, k|
@@ -105,9 +107,13 @@ class CaseIgnoringWordList < WordList
end
else
super(default, false)
- def self.[] key # :nodoc:
- super(key.downcase)
- end
+ extend Uncached
+ end
+ end
+
+ module Uncached # :nodoc:
+ def [] key
+ super(key.downcase)
end
end
@@ -121,4 +127,12 @@ class CaseIgnoringWordList < WordList
end
-end \ No newline at end of file
+end
+
+__END__
+# check memory consumption
+END {
+ ObjectSpace.each_object(CodeRay::CaseIgnoringWordList) do |wl|
+ p wl.inject(0) { |memo, key, value| memo + key.size + 24 }
+ end
+} \ No newline at end of file