From b960d03eeb2815e470c24501422cb941b21a6bda Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 13 Feb 2026 05:35:11 -0600 Subject: [PATCH] immediate ascii for string path --- source/quickjs-internal.h | 2 +- source/runtime.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/quickjs-internal.h b/source/quickjs-internal.h index afb5bb8a..681e9453 100644 --- a/source/quickjs-internal.h +++ b/source/quickjs-internal.h @@ -78,7 +78,7 @@ */ // #define DUMP_BYTECODE (1) /* dump GC summary: old/new heap, recovery %, heap growth */ -#define DUMP_GC +// #define DUMP_GC /* dump detailed GC: roots, scanning, object traversal (implies DUMP_GC) */ // #define DUMP_GC_DETAIL #ifdef DUMP_GC_DETAIL diff --git a/source/runtime.c b/source/runtime.c index 56de2c58..232aa778 100644 --- a/source/runtime.c +++ b/source/runtime.c @@ -1732,6 +1732,21 @@ static JSValue js_sub_string (JSContext *ctx, JSText *p, int start, int end) { return JS_MKPTR (p); } + /* Try immediate ASCII for short substrings (avoids heap allocation) */ + if (len <= MIST_ASCII_MAX_LEN && len > 0) { + char buf[MIST_ASCII_MAX_LEN]; + int all_ascii = 1; + for (i = 0; i < len; i++) { + uint32_t c = string_get (p, start + i); + if (c >= 128) { all_ascii = 0; break; } + buf[i] = (char)c; + } + if (all_ascii) { + JSValue imm = MIST_TryNewImmediateASCII (buf, len); + if (!JS_IsNull (imm)) return imm; + } + } + /* Root the source string as a JSValue so it survives js_alloc_string GC */ JSGCRef src_ref; JS_PushGCRef (ctx, &src_ref);