Avoid iterating multiple times in uniqueIndex for collections that might be filtered on the fly.
#8201
+14
−2