[WASM] Replace non-performance way of building String from CharArray
This commit is contained in:
@@ -55,13 +55,8 @@ internal actual fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int {
|
|||||||
@SinceKotlin("1.2")
|
@SinceKotlin("1.2")
|
||||||
@Deprecated("Use CharArray.concatToString() instead", ReplaceWith("chars.concatToString()"))
|
@Deprecated("Use CharArray.concatToString() instead", ReplaceWith("chars.concatToString()"))
|
||||||
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
||||||
public actual fun String(chars: CharArray): String {
|
public actual fun String(chars: CharArray): String =
|
||||||
var result = ""
|
chars.concatToString()
|
||||||
for (char in chars) {
|
|
||||||
result += char
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the characters from a portion of the specified array to a string.
|
* Converts the characters from a portion of the specified array to a string.
|
||||||
@@ -73,13 +68,9 @@ public actual fun String(chars: CharArray): String {
|
|||||||
@Deprecated("Use CharArray.concatToString(startIndex, endIndex) instead", ReplaceWith("chars.concatToString(offset, offset + length)"))
|
@Deprecated("Use CharArray.concatToString(startIndex, endIndex) instead", ReplaceWith("chars.concatToString(offset, offset + length)"))
|
||||||
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
|
||||||
public actual fun String(chars: CharArray, offset: Int, length: Int): String {
|
public actual fun String(chars: CharArray, offset: Int, length: Int): String {
|
||||||
if (offset < 0 || length < 0 || chars.size - offset < length)
|
if (offset < 0 || length < 0 || offset + length > chars.size)
|
||||||
throw IndexOutOfBoundsException("size: ${chars.size}; offset: $offset; length: $length")
|
throw IndexOutOfBoundsException()
|
||||||
var result = ""
|
return String.unsafeFromCharArray(chars.copyOfRange(offset, offset + length))
|
||||||
for (index in offset until offset + length) {
|
|
||||||
result += chars[index]
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user