Skip to content

Commit

Permalink
Revert "add a cache_stats methos to ObjectHash"
Browse files Browse the repository at this point in the history
This reverts commit 6727e84.
  • Loading branch information
yob committed Mar 25, 2012
1 parent 12b7bc4 commit 2625af1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
6 changes: 0 additions & 6 deletions lib/pdf/reader/object_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ObjectHash
attr_accessor :default
attr_reader :trailer, :pdf_version
attr_reader :sec_handler
attr_reader :cache_stats

# Creates a new ObjectHash object. Input can be a string with a valid filename
# or an IO-like object.
Expand All @@ -46,7 +45,6 @@ def initialize(input, opts = {})
@xref = PDF::Reader::XRef.new(@io)
@trailer = @xref.trailer
@cache = PDF::Reader::ObjectCache.new
@cache_stats = {}
@sec_handler = build_security_handler(opts)
end

Expand Down Expand Up @@ -77,17 +75,13 @@ def [](key)
unless key.is_a?(PDF::Reader::Reference)
key = PDF::Reader::Reference.new(key.to_i, 0)
end
@cache_stats[key] ||= {:hits => 0, :misses => 0}

if @cache.has_key?(key)
@cache_stats[key][:hits] += 1
@cache[key]
elsif xref[key].is_a?(Fixnum)
@cache_stats[key][:misses] += 1
buf = new_buffer(xref[key])
@cache[key] = decrypt(key, Parser.new(buf, self).object(key.id, key.gen))
elsif xref[key].is_a?(PDF::Reader::Reference)
@cache_stats[key][:misses] += 1
container_key = xref[key]
object_streams[container_key] ||= PDF::Reader::ObjectStream.new(object(container_key))
@cache[key] = object_streams[container_key][key.id]
Expand Down
64 changes: 0 additions & 64 deletions spec/object_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,67 +384,3 @@
end
end
end

describe PDF::Reader::ObjectHash, "cache_stats method" do

context "with no object lookups" do
it "should return an empty Hash" do
filename = pdf_spec_file("cairo-unicode")
h = PDF::Reader::ObjectHash.new(filename)

h.cache_stats.should be_a(Hash)
h.cache_stats.should be_empty
end
end

context "with a single object lookup" do
let!(:h) {
filename = pdf_spec_file("cairo-unicode")
h = PDF::Reader::ObjectHash.new(filename)
}

before do
h[1]
end

it "should return a Hash with a single entry" do
h.cache_stats.should be_a(Hash)
h.cache_stats.size.should == 1
end

it "should return a Hash with References as keys" do
h.cache_stats.keys.first.should be_a(PDF::Reader::Reference)
end

it "should return a Hash with hit and miss counts for each reference" do
values = h.cache_stats.values
values.should == [{:hits => 0, :misses => 1}]
end
end

context "with a two object lookups" do
let!(:h) {
filename = pdf_spec_file("cairo-unicode")
h = PDF::Reader::ObjectHash.new(filename)
}

before do
h[1]
h[1]
end

it "should return a Hash with a single entry" do
h.cache_stats.should be_a(Hash)
h.cache_stats.size.should == 1
end

it "should return a Hash with References as keys" do
h.cache_stats.keys.first.should be_a(PDF::Reader::Reference)
end

it "should return a Hash with hit and miss counts for each reference" do
values = h.cache_stats.values
values.should == [{:hits => 1, :misses => 1}]
end
end
end

0 comments on commit 2625af1

Please sign in to comment.