From 7b4994ee3574c1cc992d8eaba9862eb9c0831fa4 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 5 Mar 2025 01:47:05 +0800 Subject: [PATCH] improve performance --- include/pocketpy/interpreter/typeinfo.h | 2 +- src/interpreter/typeinfo.c | 12 ++++-------- src/public/internal.c | 5 +++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/pocketpy/interpreter/typeinfo.h b/include/pocketpy/interpreter/typeinfo.h index 9a5acf21..2f7cc63e 100644 --- a/include/pocketpy/interpreter/typeinfo.h +++ b/include/pocketpy/interpreter/typeinfo.h @@ -40,6 +40,6 @@ py_TypeInfo* TypeList__get(TypeList* self, py_Type index); py_TypeInfo* TypeList__emplace(TypeList* self); void TypeList__apply(TypeList* self, void (*f)(py_TypeInfo*, void*), void* ctx); py_TValue* TypeList__magic(py_TypeInfo* self, unsigned index); -py_TValue* TypeList__magic_readonly_nullable(py_TypeInfo* self, unsigned index); +py_TValue* TypeList__magic_readonly(py_TypeInfo* self, unsigned index); #define TypeList__magic_common(ti, index) ((ti)->magic_0 + ((index)-PK_MAGIC_SLOTS_UNCOMMON_LENGTH)) diff --git a/src/interpreter/typeinfo.c b/src/interpreter/typeinfo.c index 8e6f2e5d..35178c6b 100644 --- a/src/interpreter/typeinfo.c +++ b/src/interpreter/typeinfo.c @@ -60,18 +60,14 @@ py_TValue* TypeList__magic(py_TypeInfo* self, unsigned index) { return self->magic_1 + index; } -py_TValue* TypeList__magic_readonly_nullable(py_TypeInfo* self, unsigned index) { +py_TValue* TypeList__magic_readonly(py_TypeInfo* self, unsigned index) { if(index > __xor__) { // common magic slots - py_TValue* slot = TypeList__magic_common(self, index); - if(py_isnil(slot)) return NULL; - return slot; + return TypeList__magic_common(self, index); } // uncommon magic slots - if(self->magic_1 == NULL) return NULL; - py_TValue* slot = self->magic_1 + index; - if(py_isnil(slot)) return NULL; - return slot; + if(self->magic_1 == NULL) return py_NIL(); + return self->magic_1 + index; } #undef CHUNK_SIZE diff --git a/src/public/internal.c b/src/public/internal.c index 6516b436..e7fc7350 100644 --- a/src/public/internal.c +++ b/src/public/internal.c @@ -227,8 +227,9 @@ py_Ref py_tpfindmagic(py_Type t, py_Name name) { assert(py_ismagicname(name)); py_TypeInfo* ti = pk__type_info(t); do { - py_Ref f = TypeList__magic_readonly_nullable(ti, name); - if(f != NULL) return f; + py_Ref f = TypeList__magic_readonly(ti, name); + assert(f != NULL); + if(!py_isnil(f)) return f; ti = ti->base_ti; } while(ti); return NULL;