Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K/JS] KT-68860 Optimize listOf(element) #5401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions libraries/stdlib/js/src/kotlin/collectionJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal actual fun <T> terminateCollectionToArray(collectionSize: Int, array: A
*
* @sample samples.collections.Collections.Lists.singletonReadOnlyList
*/
public actual fun <T> listOf(element: T): List<T> = arrayListOf(element)
public actual fun <T> listOf(element: T): List<T> = ArrayList(arrayOf(element))

@PublishedApi
@SinceKotlin("1.3")
Expand Down Expand Up @@ -98,7 +98,6 @@ internal actual inline fun <K, V> buildMapInternal(capacity: Int, builderAction:
return LinkedHashMap<K, V>(capacity).apply(builderAction).build()
}


/**
* Fills the list with the provided [value].
*
Expand Down Expand Up @@ -193,7 +192,6 @@ internal actual inline fun <K, V> Map<K, V>.toSingletonMapOrSelf(): Map<K, V> =
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V> = this.toMutableMap()


@Suppress("NOTHING_TO_INLINE")
internal actual inline fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<out Any?> =
if (isVarargs)
Expand All @@ -202,8 +200,6 @@ internal actual inline fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean)
else
this.copyOf()



@PublishedApi
internal actual fun checkIndexOverflow(index: Int): Int {
if (index < 0) {
Expand All @@ -220,7 +216,6 @@ internal actual fun checkCountOverflow(count: Int): Int {
return count
}


/**
* JS map and set implementations do not make use of capacities or load factors.
*/
Expand All @@ -243,4 +238,4 @@ internal fun checkBuilderCapacity(capacity: Int) {
*
* @sample samples.collections.Maps.Instantiation.mapFromPairs
*/
public actual fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)
public actual fun <K, V> mapOf(pair: Pair<K, V>): Map<K, V> = hashMapOf(pair)