Factor out mark filtering/sorting for use in _dumpMarks()

Cleanup suggested in review of #5138. @dangoor