Optimize CPointer.toKStringFromUtf8 on Native
Use strlen and stop allocating intermediate ByteArray to make the performance comparable to ByteArray.decodeToString(). Partially fix KT-44357.
This commit is contained in:
committed by
Vasily Levchenko
parent
dc2d014504
commit
f766a3eae4
@@ -17,8 +17,10 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Alloc.h"
|
||||
#include "KString.h"
|
||||
#include "Memory.h"
|
||||
#include "MemorySharedRefs.hpp"
|
||||
#include "Types.h"
|
||||
@@ -42,4 +44,8 @@ OBJ_GETTER(Kotlin_Interop_derefStablePointer, KNativePtr pointer) {
|
||||
RETURN_OBJ(holder->ref<ErrorPolicy::kThrow>());
|
||||
}
|
||||
|
||||
OBJ_GETTER(Kotlin_CString_toKStringFromUtf8Impl, const char* cstring) {
|
||||
RETURN_RESULT_OF(StringFromUtf8Buffer, cstring, strlen(cstring));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -511,6 +511,13 @@ OBJ_GETTER(Kotlin_ByteArray_unsafeStringFromUtf8, KConstRef thiz, KInt start, KI
|
||||
RETURN_RESULT_OF(utf8ToUtf16, rawString, size);
|
||||
}
|
||||
|
||||
OBJ_GETTER(StringFromUtf8Buffer, const char* start, size_t size) {
|
||||
if (size == 0) {
|
||||
RETURN_RESULT_OF0(TheEmptyString);
|
||||
}
|
||||
RETURN_RESULT_OF(utf8ToUtf16, start, size);
|
||||
}
|
||||
|
||||
OBJ_GETTER(Kotlin_String_unsafeStringToUtf8, KString thiz, KInt start, KInt size) {
|
||||
RETURN_RESULT_OF(unsafeUtf16ToUtf8Impl<utf8::with_replacement::utf16to8>, thiz, start, size);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ OBJ_GETTER(CreateStringFromUtf8, const char* utf8, uint32_t lengthBytes);
|
||||
char* CreateCStringFromString(KConstRef kstring);
|
||||
void DisposeCString(char* cstring);
|
||||
|
||||
OBJ_GETTER(StringFromUtf8Buffer, const char* start, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user