mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
some optimize
This commit is contained in:
parent
4684e4386d
commit
4bb0ae3035
@ -12,7 +12,7 @@ typedef struct py_TypeInfo {
|
||||
struct py_TypeInfo* base_ti;
|
||||
|
||||
py_TValue self;
|
||||
py_TValue module; // the module where the type is defined
|
||||
py_GlobalRef module;
|
||||
|
||||
bool is_python; // is it a python class? (not derived from c object)
|
||||
bool is_sealed; // can it be subclassed?
|
||||
|
@ -44,7 +44,7 @@ static void py_TypeInfo__ctor(py_TypeInfo* self,
|
||||
py_Type index,
|
||||
py_Type base,
|
||||
py_TypeInfo* base_ti,
|
||||
py_TValue module) {
|
||||
py_GlobalRef module) {
|
||||
memset(self, 0, sizeof(py_TypeInfo));
|
||||
|
||||
self->name = name;
|
||||
@ -403,7 +403,7 @@ py_Type pk_newtype(const char* name,
|
||||
if(base_ti && base_ti->is_sealed) {
|
||||
c11__abort("type '%s' is not an acceptable base type", py_name2str(base_ti->name));
|
||||
}
|
||||
py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? *module : *py_NIL());
|
||||
py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? module : py_NIL());
|
||||
if(!dtor && base) dtor = base_ti->dtor;
|
||||
ti->dtor = dtor;
|
||||
ti->is_python = is_python;
|
||||
|
@ -62,11 +62,11 @@ static void PickleObject__write_bytes(PickleObject* buf, const void* data, int s
|
||||
|
||||
static void c11_sbuf__write_type_path(c11_sbuf* path_buf, py_Type type) {
|
||||
py_TypeInfo* ti = pk__type_info(type);
|
||||
if(py_isnil(&ti->module)) {
|
||||
if(py_isnil(ti->module)) {
|
||||
c11_sbuf__write_cstr(path_buf, py_name2str(ti->name));
|
||||
return;
|
||||
}
|
||||
const char* mod_path = py_tostr(py_getdict(&ti->module, __path__));
|
||||
const char* mod_path = py_tostr(py_getdict(ti->module, __path__));
|
||||
c11_sbuf__write_cstr(path_buf, mod_path);
|
||||
c11_sbuf__write_char(path_buf, '.');
|
||||
c11_sbuf__write_cstr(path_buf, py_name2str(ti->name));
|
||||
|
@ -265,7 +265,7 @@ py_Ref py_tpfindname(py_Type t, py_Name name) {
|
||||
py_Type py_tpbase(py_Type t) {
|
||||
assert(t);
|
||||
py_TypeInfo* ti = pk__type_info(t);
|
||||
return py_totype(&ti->base_ti->self);
|
||||
return ti->base;
|
||||
}
|
||||
|
||||
PK_DEPRECATED py_Ref py_tpgetmagic(py_Type type, py_Name name) {
|
||||
|
@ -101,10 +101,10 @@ static bool type__or__(int argc, py_Ref argv) {
|
||||
static bool type__module__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
py_TypeInfo* ti = pk__type_info(py_totype(argv));
|
||||
if(py_isnil(&ti->module)) {
|
||||
if(py_isnil(ti->module)) {
|
||||
py_newnone(py_retval());
|
||||
} else {
|
||||
py_Ref path = py_getdict(&ti->module, __path__);
|
||||
py_Ref path = py_getdict(ti->module, __path__);
|
||||
py_assign(py_retval(), path);
|
||||
}
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user