[K/N] Remove usage of legacy allocation stuff ^KT-52130
Merge-request: KT-MR-6182 Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
This commit is contained in:
committed by
Space
parent
cb35e868cc
commit
4a66cd0c69
@@ -24,14 +24,18 @@
|
||||
#include "KString.h"
|
||||
#include "Porting.h"
|
||||
#include "Types.h"
|
||||
#include "std_support/CStdlib.hpp"
|
||||
#include "std_support/String.hpp"
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
#include "polyhash/PolyHash.h"
|
||||
|
||||
using namespace kotlin;
|
||||
|
||||
namespace {
|
||||
|
||||
typedef std::back_insert_iterator<KStdString> KStdStringInserter;
|
||||
typedef std::back_insert_iterator<std_support::string> KStdStringInserter;
|
||||
typedef KChar* utf8to16(const char*, const char*, KChar*);
|
||||
typedef KStdStringInserter utf16to8(const KChar*,const KChar*, KStdStringInserter);
|
||||
|
||||
@@ -55,7 +59,7 @@ template<utf16to8 conversion>
|
||||
OBJ_GETTER(unsafeUtf16ToUtf8Impl, KString thiz, KInt start, KInt size) {
|
||||
RuntimeAssert(thiz->type_info() == theStringTypeInfo, "Must use String");
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(thiz, start);
|
||||
KStdString utf8;
|
||||
std_support::string utf8;
|
||||
utf8.reserve(size);
|
||||
conversion(utf16, utf16 + size, back_inserter(utf8));
|
||||
ArrayHeader* result = AllocArrayInstance(theByteArrayTypeInfo, utf8.size(), OBJ_RESULT)->array();
|
||||
@@ -118,16 +122,16 @@ char* CreateCStringFromString(KConstRef kref) {
|
||||
if (kref == nullptr) return nullptr;
|
||||
KString kstring = kref->array();
|
||||
const KChar* utf16 = CharArrayAddressOfElementAt(kstring, 0);
|
||||
KStdString utf8;
|
||||
std_support::string utf8;
|
||||
utf8.reserve(kstring->count_);
|
||||
utf8::unchecked::utf16to8(utf16, utf16 + kstring->count_, back_inserter(utf8));
|
||||
char* result = reinterpret_cast<char*>(konan::calloc(1, utf8.size() + 1));
|
||||
char* result = reinterpret_cast<char*>(std_support::calloc(1, utf8.size() + 1));
|
||||
::memcpy(result, utf8.c_str(), utf8.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
void DisposeCString(char* cstring) {
|
||||
if (cstring) konan::free(cstring);
|
||||
if (cstring) std_support::free(cstring);
|
||||
}
|
||||
|
||||
// String.kt
|
||||
|
||||
Reference in New Issue
Block a user