SORT: Don't sort Set elements if not needed.

Related to #2094.