improve performance

This commit is contained in:
blueloveTH 2025-03-05 01:47:05 +08:00
parent bd36a53226
commit 7b4994ee35
3 changed files with 8 additions and 11 deletions

View File

@ -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))

View File

@ -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

View File

@ -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;