Improve the performance of ReferencePosition.compare()