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"
  token_one = @tokens[0]
  token_two = @tokens[1]
  if token_one.is_a?(String) && token_two.is_a?(String) && token_one.match(DIGITS_ONLY) && token_two.match(DIGITS_ONLY)
    @tokens[0] = PDF::Reader::Reference.new(token_one.to_i, token_two.to_i)
    @tokens.delete_at(2)
    @tokens.delete_at(1)
  end
end