diff options
-rw-r--r-- | lib/coderay/helpers/word_list.rb | 22 |
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 |