Permalink
Browse files

memoize page resources

* this will improve performance significantly 9at the expense of memory)
  for Pages with a large number of resources
* the long term solution is to improve the ObjectCache to cache commonly
  accessed objects
  • Loading branch information...
1 parent 4ae9208 commit de71396c4021cf7c7412c3bdcf2294f02f31ae40 @yob committed Feb 6, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/pdf/reader/resource_methods.rb
View
16 lib/pdf/reader/resource_methods.rb
@@ -9,50 +9,50 @@ module ResourceMethods
# Returns a Hash of color spaces that are available to this page
#
def color_spaces
- @objects.deref!(resources[:ColorSpace]) || {}
+ @color_spaces ||= @objects.deref!(resources[:ColorSpace]) || {}
end
# Returns a Hash of fonts that are available to this page
#
def fonts
- @objects.deref!(resources[:Font]) || {}
+ @graphic_states ||= @objects.deref!(resources[:Font]) || {}
end
# Returns a Hash of external graphic states that are available to this
# page
#
def graphic_states
- @objects.deref!(resources[:ExtGState]) || {}
+ @graphic_states ||= @objects.deref!(resources[:ExtGState]) || {}
end
# Returns a Hash of patterns that are available to this page
#
def patterns
- @objects.deref!(resources[:Pattern]) || {}
+ @patterns ||= @objects.deref!(resources[:Pattern]) || {}
end
# Returns an Array of procedure sets that are available to this page
#
def procedure_sets
- @objects.deref!(resources[:ProcSet]) || []
+ @procedure_sets ||= @objects.deref!(resources[:ProcSet]) || []
end
# Returns a Hash of properties sets that are available to this page
#
def properties
- @objects.deref!(resources[:Properties]) || {}
+ @properties ||= @objects.deref!(resources[:Properties]) || {}
end
# Returns a Hash of shadings that are available to this page
#
def shadings
- @objects.deref!(resources[:Shading]) || {}
+ @shadings ||= @objects.deref!(resources[:Shading]) || {}
end
# Returns a Hash of XObjects that are available to this page
#
def xobjects
- @objects.deref!(resources[:XObject]) || {}
+ @xobjects ||= @objects.deref!(resources[:XObject]) || {}
end
end

0 comments on commit de71396

Please sign in to comment.