inlined the get_length operation

This commit is contained in:
Fabrice Bellard
2025-10-16 15:10:58 +02:00
parent c720e35d26
commit 3e5f2bbe69
2 changed files with 47 additions and 17 deletions

View File

@@ -17132,18 +17132,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
CASE(OP_push_empty_string):
*sp++ = JS_AtomToString(ctx, JS_ATOM_empty_string);
BREAK;
CASE(OP_get_length):
{
JSValue val;
sf->cur_pc = pc;
val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length);
if (unlikely(JS_IsException(val)))
goto exception;
JS_FreeValue(ctx, sp[-1]);
sp[-1] = val;
}
BREAK;
#endif
CASE(OP_push_atom_value):
*sp++ = JS_AtomToValue(ctx, get_u32(pc));
@@ -18317,7 +18305,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
}
BREAK;
#define GET_FIELD_INLINE(name, keep) \
#define GET_FIELD_INLINE(name, keep, is_length) \
{ \
JSValue val, obj; \
JSAtom atom; \
@@ -18325,8 +18313,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
JSProperty *pr; \
JSShapeProperty *prs; \
\
if (is_length) { \
atom = JS_ATOM_length; \
} else { \
atom = get_u32(pc); \
pc += 4; \
} \
\
obj = sp[-1]; \
if (likely(JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT)) { \
@@ -18370,13 +18362,19 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
CASE(OP_get_field):
GET_FIELD_INLINE(get_field, 0);
GET_FIELD_INLINE(get_field, 0, 0);
BREAK;
CASE(OP_get_field2):
GET_FIELD_INLINE(get_field2, 1);
GET_FIELD_INLINE(get_field2, 1, 0);
BREAK;
#if SHORT_OPCODES
CASE(OP_get_length):
GET_FIELD_INLINE(get_length, 0, 1);
BREAK;
#endif
CASE(OP_put_field):
{
int ret;

View File

@@ -425,6 +425,21 @@ function array_slice(n)
return len * n;
}
function array_length_read(n)
{
var tab, sum, j;
tab = [1, 2, 3];
sum = 0;
for(j = 0; j < n; j++) {
sum += tab.length;
sum += tab.length;
sum += tab.length;
sum += tab.length;
}
global_res = sum;
return n * 4;
}
function array_length_decr(n)
{
var tab, ref, i, j, len;
@@ -929,6 +944,21 @@ function regexp_utf16(n)
return n * 1000;
}
function string_length(n)
{
var str, sum, j;
str = "abcde";
sum = 0;
for(j = 0; j < n; j++) {
sum += str.length;
sum += str.length;
sum += str.length;
sum += str.length;
}
global_res = sum;
return n * 4;
}
/* incremental string contruction as local var */
function string_build1(n)
{
@@ -1382,6 +1412,7 @@ function main(argc, argv, g)
array_update,
array_prop_create,
array_slice,
array_length_read,
array_length_decr,
array_hole_length_decr,
array_push,
@@ -1411,6 +1442,7 @@ function main(argc, argv, g)
math_min,
regexp_ascii,
regexp_utf16,
string_length,
string_build1,
string_build1x,
string_build2c,