summaryrefslogtreecommitdiff
path: root/lib/coderay/tokens.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2005-09-28 01:39:48 +0000
committermurphy <murphy@rubychan.de>2005-09-28 01:39:48 +0000
commitf9bb65b346b27fe507c1e1bd31c9451b99b2a9a5 (patch)
tree464e7008663f0b3e99ea41cebc2dbdc5fe6c72fc /lib/coderay/tokens.rb
parent763e5b8b4d27fae528097263007d8113d444e69d (diff)
downloadcoderay-f9bb65b346b27fe507c1e1bd31c9451b99b2a9a5.tar.gz
enhanced CodeRay interface
updated demo_css.rb Rakefile: rdoc_small task added
Diffstat (limited to 'lib/coderay/tokens.rb')
-rw-r--r--lib/coderay/tokens.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb
index 71ad33a..988008e 100644
--- a/lib/coderay/tokens.rb
+++ b/lib/coderay/tokens.rb
@@ -151,9 +151,15 @@ module CodeRay
# This can not be undone, but should yield the same output
# in most Encoders. It basically makes the output smaller.
#
- # Combined with dump, it saves database space.
+ # Combined with dump, it saves space for the cost
+ # calculating time.
+ #
+ # If the scanner is written carefully, this is not required -
+ # for example, consecutive //-comment lines can already be
+ # joined in one token by the Scanner.
def optimize
- last_kind, last_text = nil, nil
+ print ' Tokens#optimize: before: %d - ' % size if $DEBUG
+ last_kind = last_text = nil
new = self.class.new
each do |text, kind|
if text.is_a? String
@@ -166,15 +172,17 @@ module CodeRay
end
else
new << [last_text, last_kind] if last_kind
- last_kind, last_text = nil, nil
+ last_kind = last_text = nil
new << [text, kind]
end
end
new << [last_text, last_kind] if last_kind
+ print 'after: %d (%d saved = %2.0f%%)' %
+ [new.size, size - new.size, 1.0 - (new.size.to_f / size)] if $DEBUG
new
end
- # Compact the object itself; see compact.
+ # Compact the object itself; see optimize.
def optimize!
replace optimize
end
@@ -290,9 +298,9 @@ module CodeRay
raise NotImplementedError, 'A TokenStream cannot be dumped.'
end
- # A TokenStream cannot be compacted. Use Tokens.
- def compact
- raise NotImplementedError, 'A TokenStream cannot be compacted.'
+ # A TokenStream cannot be optimized. Use Tokens.
+ def optimize
+ raise NotImplementedError, 'A TokenStream cannot be optimized.'
end
end