mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add inline optimize
This commit is contained in:
parent
9b8f706010
commit
f9f74b7b12
@ -61,3 +61,15 @@
|
||||
#else
|
||||
#define PK_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#if defined(__GNUC__)
|
||||
#define PK_INLINE __attribute__((always_inline)) inline
|
||||
#elif defined(_MSC_VER)
|
||||
#define PK_INLINE __forceinline
|
||||
#else
|
||||
#define PK_INLINE inline
|
||||
#endif
|
||||
#else
|
||||
#define PK_INLINE
|
||||
#endif
|
||||
|
@ -92,7 +92,6 @@ bool pk__parse_int_slice(py_Ref slice,
|
||||
bool pk__normalize_index(int* index, int length);
|
||||
|
||||
bool pk__object_new(int argc, py_Ref argv);
|
||||
py_TypeInfo* pk_typeinfo(py_Type type);
|
||||
|
||||
bool pk_wrapper__self(int argc, py_Ref argv);
|
||||
|
||||
|
@ -10,17 +10,17 @@ py_ItemRef pk_tpfindname(py_TypeInfo* ti, py_Name name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
py_ItemRef py_tpfindname(py_Type type, py_Name name) {
|
||||
PK_INLINE py_ItemRef py_tpfindname(py_Type type, py_Name name) {
|
||||
py_TypeInfo* ti = pk_typeinfo(type);
|
||||
return pk_tpfindname(ti, name);
|
||||
}
|
||||
|
||||
py_Ref py_tpfindmagic(py_Type t, py_Name name) {
|
||||
PK_INLINE py_Ref py_tpfindmagic(py_Type t, py_Name name) {
|
||||
// assert(py_ismagicname(name));
|
||||
return py_tpfindname(t, name);
|
||||
}
|
||||
|
||||
py_Type py_tpbase(py_Type t) {
|
||||
PK_INLINE py_Type py_tpbase(py_Type t) {
|
||||
assert(t);
|
||||
py_TypeInfo* ti = pk_typeinfo(t);
|
||||
return ti->base;
|
||||
@ -44,7 +44,7 @@ const char* py_tpname(py_Type type) {
|
||||
return py_name2str(name);
|
||||
}
|
||||
|
||||
py_TypeInfo* pk_typeinfo(py_Type type) {
|
||||
PK_INLINE py_TypeInfo* pk_typeinfo(py_Type type) {
|
||||
#ifndef NDEBUG
|
||||
int length = pk_current_vm->types.length;
|
||||
if(type < 0 || type >= length) {
|
||||
|
@ -6,6 +6,18 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define HASH_PROBE_0(__k, ok, i) \
|
||||
ok = false; \
|
||||
i = (uintptr_t)(__k)&self->mask; \
|
||||
do { \
|
||||
if(self->items[i].key == (__k)) { \
|
||||
ok = true; \
|
||||
break; \
|
||||
} \
|
||||
if(self->items[i].key == NULL) break; \
|
||||
i = (5 * i + 1) & self->mask; \
|
||||
} while(true);
|
||||
|
||||
#define HASH_PROBE_1(__k, ok, i) \
|
||||
ok = false; \
|
||||
i = (uintptr_t)(__k)&self->mask; \
|
||||
@ -17,8 +29,6 @@
|
||||
i = (5 * i + 1) & self->mask; \
|
||||
}
|
||||
|
||||
#define HASH_PROBE_0 HASH_PROBE_1
|
||||
|
||||
static void NameDict__set_capacity_and_alloc_items(NameDict* self, int val) {
|
||||
self->capacity = val;
|
||||
self->critical_size = val * self->load_factor;
|
||||
|
@ -2,14 +2,16 @@
|
||||
#include "pocketpy/pocketpy.h"
|
||||
#include <assert.h>
|
||||
|
||||
void* PyObject__userdata(PyObject* self) { return self->flex + PK_OBJ_SLOTS_SIZE(self->slots); }
|
||||
PK_INLINE void* PyObject__userdata(PyObject* self) {
|
||||
return self->flex + PK_OBJ_SLOTS_SIZE(self->slots);
|
||||
}
|
||||
|
||||
NameDict* PyObject__dict(PyObject* self) {
|
||||
PK_INLINE NameDict* PyObject__dict(PyObject* self) {
|
||||
assert(self->slots == -1);
|
||||
return (NameDict*)(self->flex);
|
||||
}
|
||||
|
||||
py_TValue* PyObject__slots(PyObject* self) {
|
||||
PK_INLINE py_TValue* PyObject__slots(PyObject* self) {
|
||||
assert(self->slots >= 0);
|
||||
return (py_TValue*)(self->flex);
|
||||
}
|
@ -178,7 +178,7 @@ bool py_vectorcall(uint16_t argc, uint16_t kwargc) {
|
||||
return VM__vectorcall(pk_current_vm, argc, kwargc, false) != RES_ERROR;
|
||||
}
|
||||
|
||||
py_Ref py_retval() { return &pk_current_vm->last_retval; }
|
||||
PK_INLINE py_Ref py_retval() { return &pk_current_vm->last_retval; }
|
||||
|
||||
bool py_pushmethod(py_Name name) {
|
||||
bool ok = pk_loadmethod(py_peek(-1), name);
|
||||
|
@ -8,12 +8,12 @@ py_Ref py_getreg(int i) { return pk_current_vm->reg + i; }
|
||||
|
||||
void py_setreg(int i, py_Ref val) { pk_current_vm->reg[i] = *val; }
|
||||
|
||||
py_Ref py_getdict(py_Ref self, py_Name name) {
|
||||
PK_INLINE py_Ref py_getdict(py_Ref self, py_Name name) {
|
||||
assert(self && self->is_ptr);
|
||||
return NameDict__try_get(PyObject__dict(self->_obj), name);
|
||||
}
|
||||
|
||||
void py_setdict(py_Ref self, py_Name name, py_Ref val) {
|
||||
PK_INLINE void py_setdict(py_Ref self, py_Name name, py_Ref val) {
|
||||
assert(self && self->is_ptr);
|
||||
NameDict__set(PyObject__dict(self->_obj), name, val);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "pocketpy/objects/object.h"
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
|
||||
bool py_istype(py_Ref self, py_Type type) { return self->type == type; }
|
||||
PK_INLINE bool py_istype(py_Ref self, py_Type type) { return self->type == type; }
|
||||
|
||||
bool py_checktype(py_Ref self, py_Type type) {
|
||||
if(self->type == type) return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user