Skip to content

Commit 4f2fc30

Browse files
committed
HPy: native fast-path for HPy_Type if it is a boxed handle
1 parent e8179b4 commit 4f2fc30

File tree

1 file changed

+14
-0
lines changed
  • graalpython/com.oracle.graal.python.jni/src

1 file changed

+14
-0
lines changed

graalpython/com.oracle.graal.python.jni/src/hpy_jni.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static HPy (*original_Global_Load)(HPyContext *ctx, HPyGlobal global);
260260
static void (*original_Field_Store)(HPyContext *ctx, HPy target_object, HPyField *target_field, HPy h);
261261
static HPy (*original_Field_Load)(HPyContext *ctx, HPy source_object, HPyField source_field);
262262
static int (*original_Is)(HPyContext *ctx, HPy a, HPy b);
263+
static HPy (*original_Type)(HPyContext *, HPy);
263264

264265
static int augment_Is(HPyContext *ctx, HPy a, HPy b) {
265266
long bitsA = toBits(a);
@@ -577,6 +578,17 @@ HPy augment_GetItem_s(HPyContext *ctx, HPy target, const char *name) {
577578
return DO_UPCALL_HPY(CONTEXT_INSTANCE(ctx), GetItems, target, jname);
578579
}
579580

581+
HPy augment_Type(HPyContext *ctx, HPy h) {
582+
uint64_t bits = toBits(h);
583+
if (isBoxedInt(bits)) {
584+
return ctx->h_LongType;
585+
} else if (isBoxedDouble(bits)) {
586+
return ctx->h_FloatType;
587+
} else {
588+
return original_Type(ctx, h);
589+
}
590+
}
591+
580592
void initDirectFastPaths(HPyContext *context) {
581593
LOG("%p", context);
582594
context->name = "HPy Universal ABI (GraalVM backend, JNI)";
@@ -633,6 +645,8 @@ void initDirectFastPaths(HPyContext *context) {
633645

634646
AUGMENT(Is);
635647

648+
AUGMENT(Type);
649+
636650
#undef AUGMENT
637651

638652
context->ctx_SetItem_s = augment_SetItem_s;

0 commit comments

Comments
 (0)