Optimize Ref_toString().

I have a large PDF where this function is called 1.6 million times
during loading. Minimizing the string concatenations reduces the
cumulative allocations done by Firefox within this function from 113 MB
to 48 MB.
Merge pull request #5078 from nnethercote/Ref-toString

Optimize Ref_toString().