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
The Kotlin Standard Library
This module creates the standard library for Kotlin.
Notes for contributors
We use code generation to generate utility extension functions for some collection-like types like arrays, strings, Collection<T>, Sequence<T>, Map<K, V> etc.
These sources are placed into the generated folder and their names are prefixed with an underscore, for example, generated/_Collections.kt
To run the code generator, use the following command in the root directory of the project:
./gradlew :tools:kotlin-stdlib-gen:run
Note: on Windows type
gradlewwithout the leading./
This then runs the script which generates a significant part of stdlib sources from the templates written in a special Kotlin-based DSL.
Usage samples
If you want to author samples for the standard library, please head to the samples readme.