forked from cory/tildefriends
Wow, load was slow because websocket sends were slow, because TextEcoder was slow. Do it in C.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3796 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -9,6 +9,21 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static JSValue _util_utf8_encode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
size_t length = 0;
|
||||
const char* value = JS_ToCStringLen(context, &length, argv[0]);
|
||||
JSValue arrayBuffer = JS_NewArrayBufferCopy(context, (const uint8_t*)value, length);
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue constructor = JS_GetPropertyStr(context, global, "Uint8Array");
|
||||
JS_FreeValue(context, global);
|
||||
JSValue typedArray = JS_CallConstructor(context, constructor, 1, &arrayBuffer);
|
||||
JS_FreeValue(context, constructor);
|
||||
JS_FreeValue(context, arrayBuffer);
|
||||
JS_FreeCString(context, value);
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
static JSValue _util_utf8_decode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_NULL;
|
||||
@ -184,6 +199,7 @@ void tf_util_register(JSContext* context)
|
||||
{
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JS_SetPropertyStr(context, global, "utf8Decode", JS_NewCFunction(context, _util_utf8_decode, "utf8Decode", 1));
|
||||
JS_SetPropertyStr(context, global, "utf8Encode", JS_NewCFunction(context, _util_utf8_encode, "utf8Encode", 1));
|
||||
JS_SetPropertyStr(context, global, "print", JS_NewCFunction(context, _util_print, "print", 1));
|
||||
JS_SetPropertyStr(context, global, "setTimeout", JS_NewCFunction(context, _util_setTimeout, "setTimeout", 2));
|
||||
JS_FreeValue(context, global);
|
||||
|
Reference in New Issue
Block a user