Skip to content

Commit e5de89f

Browse files
author
Fabrice Bellard
committed
optimized post_inc and post_dec
1 parent 8e8eefb commit e5de89f

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

quickjs.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19045,11 +19045,42 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1904519045
}
1904619046
BREAK;
1904719047
CASE(OP_post_inc):
19048+
{
19049+
JSValue op1;
19050+
int val;
19051+
op1 = sp[-1];
19052+
if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {
19053+
val = JS_VALUE_GET_INT(op1);
19054+
if (unlikely(val == INT32_MAX))
19055+
goto post_inc_slow;
19056+
sp[0] = JS_NewInt32(ctx, val + 1);
19057+
} else {
19058+
post_inc_slow:
19059+
sf->cur_pc = pc;
19060+
if (js_post_inc_slow(ctx, sp, opcode))
19061+
goto exception;
19062+
}
19063+
sp++;
19064+
}
19065+
BREAK;
1904819066
CASE(OP_post_dec):
19049-
sf->cur_pc = pc;
19050-
if (js_post_inc_slow(ctx, sp, opcode))
19051-
goto exception;
19052-
sp++;
19067+
{
19068+
JSValue op1;
19069+
int val;
19070+
op1 = sp[-1];
19071+
if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) {
19072+
val = JS_VALUE_GET_INT(op1);
19073+
if (unlikely(val == INT32_MIN))
19074+
goto post_dec_slow;
19075+
sp[0] = JS_NewInt32(ctx, val - 1);
19076+
} else {
19077+
post_dec_slow:
19078+
sf->cur_pc = pc;
19079+
if (js_post_inc_slow(ctx, sp, opcode))
19080+
goto exception;
19081+
}
19082+
sp++;
19083+
}
1905319084
BREAK;
1905419085
CASE(OP_inc_loc):
1905519086
{

0 commit comments

Comments
 (0)