Make empty array handling more efficient, also fixes KT-21758 (#1285)
* Make empty array handling more efficient, also fixes KT-21758 * Fix WebAssembly.
This commit is contained in:
@@ -39,6 +39,14 @@ static inline void copyImpl(KConstRef thiz, KInt fromIndex,
|
||||
count * sizeof(T));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
const ArrayHeader anEmptyArray = {
|
||||
theArrayTypeInfo, /* permanent object */ 0, /* element count */ 0
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
// TODO: those must be compiler intrinsics afterwards.
|
||||
@@ -98,6 +106,10 @@ void Kotlin_Array_copyImpl(KConstRef thiz, KInt fromIndex,
|
||||
}
|
||||
|
||||
// Arrays.kt
|
||||
OBJ_GETTER0(Kotlin_emptyArray) {
|
||||
RETURN_OBJ(const_cast<ObjHeader*>(anEmptyArray.obj()));
|
||||
}
|
||||
|
||||
KByte Kotlin_ByteArray_get(KConstRef thiz, KInt index) {
|
||||
const ArrayHeader* array = thiz->array();
|
||||
if (static_cast<uint32_t>(index) >= array->count_) {
|
||||
|
||||
@@ -71,7 +71,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
extern const TypeInfo* theAnyTypeInfo;
|
||||
extern const TypeInfo* theCloneableTypeInfo;
|
||||
extern const TypeInfo* theArrayTypeInfo;
|
||||
extern const TypeInfo* theByteArrayTypeInfo;
|
||||
extern const TypeInfo* theCharArrayTypeInfo;
|
||||
|
||||
@@ -12667,10 +12667,8 @@ public inline fun <reified T> Collection<T>.toTypedArray(): Array<T> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <reified @PureReifiable T> arrayOf(vararg elements: T): Array<T> = elements as Array<T>
|
||||
|
||||
private val kEmptyArray = arrayOf<Any>()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <T> emptyArray() = kEmptyArray as Array<T>
|
||||
@SymbolName("Kotlin_emptyArray")
|
||||
external public fun <T> emptyArray(): Array<T>
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Double] numbers.
|
||||
|
||||
Reference in New Issue
Block a user