Use a sorted index instead of sorting in-place in html5lib serializer