class PDF::Reader::Buffer
def merge_indirect_reference
expensive regexp checks if possible.
indirect reference, so test for that case first and avoid the relatively
It's incredibly likely that the next 3 tokens in the buffer are NOT an
that extra check.
like an indirect object. For optimisation reasons, I'd rather avoid
code further up the stack would need to check every token to see if it looks
Merging them into a single string was another option, but that would mean
them, replace the tokens with a PDF::Reader::Reference instance.
detect a series of 3 tokens that make up an indirect object. If we find
def merge_indirect_reference return if @tokens.size < 3 return if @tokens[2] != "R" if @tokens[0].match(/\d+/) && @tokens[1].match(/\d+/) @tokens[0] = PDF::Reader::Reference.new(@tokens[0].to_i, @tokens[1].to_i) @tokens[1] = nil @tokens[2] = nil @tokens.compact! end end