Permalink
Browse files

Revert "add a cache_stats methos to ObjectHash"

This reverts commit 6727e84.
  • Loading branch information...
1 parent 12b7bc4 commit 2625af19808b29d440352a49a1052e4a616872b6 @yob committed Mar 25, 2012
Showing with 0 additions and 70 deletions.
  1. +0 −6 lib/pdf/reader/object_hash.rb
  2. +0 −64 spec/object_hash_spec.rb
@@ -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.
@@ -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
@@ -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]
View
@@ -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.