Efficient implementation of printRelations.

The string construction and sorting turned out to be very expensive
on large analyses. This implementation is about 10x faster.