immediate ascii for string path
This commit is contained in:
@@ -78,7 +78,7 @@
|
|||||||
*/
|
*/
|
||||||
// #define DUMP_BYTECODE (1)
|
// #define DUMP_BYTECODE (1)
|
||||||
/* dump GC summary: old/new heap, recovery %, heap growth */
|
/* 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) */
|
/* dump detailed GC: roots, scanning, object traversal (implies DUMP_GC) */
|
||||||
// #define DUMP_GC_DETAIL
|
// #define DUMP_GC_DETAIL
|
||||||
#ifdef DUMP_GC_DETAIL
|
#ifdef DUMP_GC_DETAIL
|
||||||
|
|||||||
@@ -1732,6 +1732,21 @@ static JSValue js_sub_string (JSContext *ctx, JSText *p, int start, int end) {
|
|||||||
return JS_MKPTR (p);
|
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 */
|
/* Root the source string as a JSValue so it survives js_alloc_string GC */
|
||||||
JSGCRef src_ref;
|
JSGCRef src_ref;
|
||||||
JS_PushGCRef (ctx, &src_ref);
|
JS_PushGCRef (ctx, &src_ref);
|
||||||
|
|||||||
Reference in New Issue
Block a user