Skip to content

Simplify and optimize OP_rest #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ static __exception int js_set_length64(JSContext *ctx, JSValue obj,
static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len);
static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
JSValue array_arg);
static JSValue js_create_array(JSContext *ctx, int len, JSValue *tab);
static bool js_get_fast_array(JSContext *ctx, JSValue obj,
JSValue **arrpp, uint32_t *countp);
static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,
Expand Down Expand Up @@ -13713,26 +13714,6 @@ static JSValue js_build_mapped_arguments(JSContext *ctx, int argc,
return JS_EXCEPTION;
}

static JSValue js_build_rest(JSContext *ctx, int first, int argc, JSValue *argv)
{
JSValue val;
int i, ret;

val = JS_NewArray(ctx);
if (JS_IsException(val))
return val;
for (i = first; i < argc; i++) {
ret = JS_DefinePropertyValueUint32(ctx, val, i - first,
js_dup(argv[i]),
JS_PROP_C_W_E);
if (ret < 0) {
JS_FreeValue(ctx, val);
return JS_EXCEPTION;
}
}
return val;
}

static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)
{
JSObject *p;
Expand Down Expand Up @@ -15148,9 +15129,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
BREAK;
CASE(OP_rest):
{
int first = get_u16(pc);
int i, n, first = get_u16(pc);
pc += 2;
*sp++ = js_build_rest(ctx, first, argc, argv);
i = min_int(first, argc);
n = argc - i;
*sp++ = js_create_array(ctx, n, &argv[i]);
if (unlikely(JS_IsException(sp[-1])))
goto exception;
}
Expand Down