Skip to content

Commit e423275

Browse files
committed
remove dump/undump functionality
1 parent 8e67efe commit e423275

File tree

5 files changed

+15
-138
lines changed

5 files changed

+15
-138
lines changed

bench/bench.rb

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
lang = ARGV.fetch(0) do
1515
puts <<-HELP
1616
Usage:
17-
ruby bench.rb (c|ruby|dump) (null|text|tokens|count|statistic|yaml|html) [size in kB] [stream]
17+
ruby bench.rb (c|ruby) (null|text|tokens|count|statistic|yaml|html) [size in kB] [stream]
1818
1919
SIZE defaults to 100 kB (= 100,000 bytes).
2020
SIZE = 0 means the whole input.
21-
SIZE is ignored when dump is input.
2221
2322
-p generates a profile (slow! use with SIZE = 1)
2423
-o shows the output
@@ -48,10 +47,6 @@
4847
end
4948
end
5049

51-
$dump_input = lang == 'dump'
52-
$dump_output = format == 'dump'
53-
require 'coderay/helpers/gzip_simple.rb' if $dump_input
54-
5550
def here fn = nil
5651
return MYDIR unless fn
5752
File.join here, fn
@@ -66,59 +61,38 @@ def here fn = nil
6661

6762
data = nil
6863
File.open(here("#$filename." + lang), 'rb') { |f| data = f.read }
69-
if $dump_input
70-
@size = CodeRay::Tokens.load(data).text.size
71-
else
72-
raise 'Example file is empty.' if data.empty?
73-
unless @size.zero?
74-
data += data until data.size >= @size
75-
data = data[0, @size]
76-
end
77-
@size = data.size
64+
raise 'Example file is empty.' if data.empty?
65+
unless @size.zero?
66+
data += data until data.size >= @size
67+
data = data[0, @size]
7868
end
79-
69+
@size = data.size
70+
8071
options = {
8172
:tab_width => 2,
8273
# :line_numbers => :inline,
8374
:css => $style ? :style : :class,
8475
}
85-
$hl = CodeRay.encoder(format, options) unless $dump_output
76+
$hl = CodeRay.encoder(format, options)
8677
time = bm.report('CodeRay') do
8778
if $stream || true
88-
if $dump_input
89-
raise 'Can\'t stream dump.'
90-
elsif $dump_output
91-
raise 'Can\'t dump stream.'
92-
end
9379
$o = $hl.encode(data, lang, options)
9480
else
95-
if $dump_input
96-
tokens = CodeRay::Tokens.load data
97-
else
98-
tokens = CodeRay.scan(data, lang)
99-
end
81+
tokens = CodeRay.scan(data, lang)
10082
tokens.optimize! if $optimize
101-
if $dump_output
102-
$o = tokens.optimize.dump
103-
else
104-
$o = tokens.encode($hl)
105-
end
83+
$o = tokens.encode($hl)
10684
end
10785
end
108-
$file_created = here('test.' +
109-
($dump_output ? 'dump' : $hl.file_extension))
86+
$file_created = here('test.' + $hl.file_extension)
11087
File.open($file_created, 'wb') do |f|
11188
# f.write $o
11289
end
113-
Dir.chdir(here) do
114-
FileUtils.copy 'test.dump', 'example.dump' if $dump_output
115-
end
116-
90+
11791
time_real = time.real
118-
92+
11993
puts "\t%7.2f KB/s (%d.%d KB)" % [((@size / 1000.0) / time_real), @size / 1000, @size % 1000]
12094
puts $o if ARGV.include? '-o'
121-
95+
12296
end
12397
end
12498
puts "Files created: #$file_created"

lib/coderay/encoders/debug.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Encoders
99
#
1010
# You cannot fully restore the tokens information from the
1111
# output, because consecutive :space tokens are merged.
12-
# Use Tokens#dump for caching purposes.
1312
#
1413
# See also: Scanners::Debug
1514
class Debug < Encoder

lib/coderay/helpers/gzip.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.

lib/coderay/tokens.rb

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module CodeRay
22

3-
# GZip library for writing and reading token dumps.
4-
autoload :GZip, coderay_path('helpers', 'gzip')
5-
63
# = Tokens TODO: Rewrite!
74
#
85
# The Tokens class represents a list of tokens returnd from
@@ -45,8 +42,7 @@ module CodeRay
4542
# See how small it is? ;)
4643
#
4744
# Tokens gives you the power to handle pre-scanned code very easily:
48-
# You can convert it to a webpage, a YAML file, or dump it into a gzip'ed string
49-
# that you put in your DB.
45+
# You can convert it to a webpage, a YAML file, or a .raydebug representation.
5046
#
5147
# It also allows you to generate tokens directly (without using a scanner),
5248
# to load them from a file, and still use any Encoder that CodeRay provides.
@@ -157,53 +153,11 @@ def split_into_parts *sizes
157153
parts
158154
end
159155

160-
# Dumps the object into a String that can be saved
161-
# in files or databases.
162-
#
163-
# The dump is created with Marshal.dump;
164-
# In addition, it is gzipped using GZip.gzip.
165-
#
166-
# The returned String object includes Undumping
167-
# so it has an #undump method. See Tokens.load.
168-
#
169-
# You can configure the level of compression,
170-
# but the default value 7 should be what you want
171-
# in most cases as it is a good compromise between
172-
# speed and compression rate.
173-
#
174-
# See GZip module.
175-
def dump gzip_level = 7
176-
dump = Marshal.dump self
177-
dump = GZip.gzip dump, gzip_level
178-
dump.extend Undumping
179-
end
180-
181156
# Return the actual number of tokens.
182157
def count
183158
size / 2
184159
end
185160

186-
# Include this module to give an object an #undump
187-
# method.
188-
#
189-
# The string returned by Tokens.dump includes Undumping.
190-
module Undumping
191-
# Calls Tokens.load with itself.
192-
def undump
193-
Tokens.load self
194-
end
195-
end
196-
197-
# Undump the object using Marshal.load, then
198-
# unzip it using GZip.gunzip.
199-
#
200-
# The result is commonly a Tokens object, but
201-
# this is not guaranteed.
202-
def Tokens.load dump
203-
dump = GZip.gunzip dump
204-
@dump = Marshal.load dump
205-
end
206-
207161
alias text_token push
208162
def begin_group kind; push :begin_group, kind end
209163
def end_group kind; push :end_group, kind end

test/unit/tokens.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ def test_adding_tokens
1818
assert_equal tokens.count, 4
1919
end
2020

21-
def test_dump_undump
22-
tokens = make_tokens
23-
tokens2 = nil
24-
assert_nothing_raised do
25-
tokens2 = tokens.dump.undump
26-
end
27-
assert_equal tokens, tokens2
28-
end
29-
3021
def test_to_s
3122
assert_equal 'string()', make_tokens.to_s
3223
end

0 commit comments

Comments
 (0)