368f21461c
Sequence::toSet and Sequence::toList both create a collection, fill it with elements, and then try to optimize a result by returning empty, singleton, or the allocated collection depending on the elements count. Instead of allocating the collection and then trying to return an optimized instance it is worth checking the sequence's size beforehand and return empty/singleton collection when possible. Proposed change optimize performance of aforementioned functions and also reduce allocation rate when a sequence consists of 0 or 1 elements. ^KT-55091 fixed