Skip to content

Commit 4bed95d

Browse files
committed
feat: add property to inline cache
1 parent 5ccbbdc commit 4bed95d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/core/object.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ int delete_property(JSContext* ctx, JSObject* p, JSAtom atom) {
273273
pr->flags = 0;
274274
pr->atom = JS_ATOM_NULL;
275275
pr1->u.value = JS_UNDEFINED;
276-
if (ic_delete_shape_proto_watchpoints(ctx->rt, sh, atom))
277-
return -1;
276+
ic_delete_shape_proto_watchpoints(ctx->rt, sh, atom);
278277
/* compact the properties if too many deleted properties */
279278
if (sh->deleted_prop_count >= 8 && sh->deleted_prop_count >= ((unsigned)sh->prop_count / 2))
280279
compact_properties(ctx, p);
@@ -1774,7 +1773,8 @@ int JS_SetPropertyInternal(JSContext* ctx, JSValueConst this_obj, JSAtom prop, J
17741773
JSProperty* pr;
17751774
uint32_t tag;
17761775
JSPropertyDescriptor desc;
1777-
int ret, offset;
1776+
uint32_t offset;
1777+
int ret;
17781778
#if 0
17791779
printf("JS_SetPropertyInternal: "); print_atom(ctx, prop); printf("\n");
17801780
#endif
@@ -1969,14 +1969,17 @@ int JS_SetPropertyInternal(JSContext* ctx, JSValueConst this_obj, JSAtom prop, J
19691969
}
19701970
}
19711971

1972-
if (ic_delete_shape_proto_watchpoints(ctx->rt, p->shape, prop))
1973-
return -1;
1972+
ic_delete_shape_proto_watchpoints(ctx->rt, p->shape, prop);
19741973
pr = add_property(ctx, p, prop, JS_PROP_C_W_E);
19751974
if (unlikely(!pr)) {
19761975
JS_FreeValue(ctx, val);
19771976
return -1;
19781977
}
19791978
pr->u.value = val;
1979+
if (ic && p->shape->is_hashed) {
1980+
ic->updated = TRUE;
1981+
ic->updated_offset = add_ic_slot(ic, prop, p, p->shape->prop_count - 1, NULL);
1982+
}
19801983
return TRUE;
19811984
}
19821985

src/core/runtime.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ int JS_SetPrototypeInternal(JSContext* ctx, JSValueConst obj, JSValueConst proto
355355
if (js_shape_prepare_update(ctx, p, NULL))
356356
return -1;
357357
sh = p->shape;
358-
if (ic_free_shape_proto_watchpoints(ctx->rt, p->shape))
359-
return -1;
358+
ic_free_shape_proto_watchpoints(ctx->rt, p->shape);
360359
if (sh->proto)
361360
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, sh->proto));
362361
sh->proto = proto;

src/core/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ typedef struct JSVarDef {
511511
#define PC2COLUMN_RANGE 5
512512
#define PC2COLUMN_OP_FIRST 1
513513
#define PC2COLUMN_DIFF_PC_MAX ((255 - PC2COLUMN_OP_FIRST) / PC2COLUMN_RANGE)
514-
#define IC_CACHE_ITEM_CAPACITY 8
514+
#define IC_CACHE_ITEM_CAPACITY 2
515515

516516
typedef enum JSFunctionKindEnum {
517517
JS_FUNC_NORMAL = 0,

0 commit comments

Comments
 (0)