[Wasm] Improve string constructor in stdlib

This commit is contained in:
Igor Laevsky
2021-10-22 21:16:04 +03:00
parent 8dc81b6c57
commit 46b56c7642
6 changed files with 32 additions and 11 deletions
@@ -12,8 +12,11 @@ import kotlin.math.min
* The `String` class represents character strings. All string literals in Kotlin programs, such as `"abc"`, are
* implemented as instances of this class.
*/
public class String internal constructor(internal val chars: CharArray) : Comparable<String>, CharSequence {
public companion object;
public class String private constructor(internal val chars: CharArray) : Comparable<String>, CharSequence {
public companion object {
// Note: doesn't copy the array, use with care.
internal fun unsafeFromCharArray(chars: CharArray) = String(chars)
}
/**
* Returns a string obtained by concatenating this string with the string representation of the given [other] object.
@@ -68,4 +71,4 @@ public class String internal constructor(internal val chars: CharArray) : Compar
}
}
internal fun stringLiteral(startAddr: Int, length: Int) = String(unsafeRawMemoryToCharArray(startAddr, length))
internal fun stringLiteral(startAddr: Int, length: Int) = String.unsafeFromCharArray(unsafeRawMemoryToCharArray(startAddr, length))