From 7550bba0a46f791bf4e052617542a33250ca5cd3 Mon Sep 17 00:00:00 2001 From: murphy Date: Wed, 30 Dec 2009 07:08:12 +0000 Subject: Documentation: Added warning about WordList caching. --- lib/coderay/helpers/word_list.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/coderay/helpers') 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 -- cgit v1.2.1