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:
2022-01-27 01:15:54 +00:00
parent 7b32067b07
commit 9fd4be0e4a
6 changed files with 23 additions and 3358 deletions

View File

@ -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);