diff --git a/include/pocketpy/export.h b/include/pocketpy/export.h index d115a8e0..44104bae 100644 --- a/include/pocketpy/export.h +++ b/include/pocketpy/export.h @@ -60,4 +60,16 @@ #define PK_DEPRECATED __attribute__((deprecated)) #else #define PK_DEPRECATED -#endif \ No newline at end of file +#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 diff --git a/include/pocketpy/interpreter/vm.h b/include/pocketpy/interpreter/vm.h index b596ba51..816f760f 100644 --- a/include/pocketpy/interpreter/vm.h +++ b/include/pocketpy/interpreter/vm.h @@ -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); diff --git a/src/interpreter/typeinfo.c b/src/interpreter/typeinfo.c index d8a07756..c3d2172a 100644 --- a/src/interpreter/typeinfo.c +++ b/src/interpreter/typeinfo.c @@ -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) { diff --git a/src/objects/namedict.c b/src/objects/namedict.c index ac87e95a..7c21eb24 100644 --- a/src/objects/namedict.c +++ b/src/objects/namedict.c @@ -6,6 +6,18 @@ #include #include +#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; diff --git a/src/objects/object.c b/src/objects/object.c index 1e104aed..1a3f7ef4 100644 --- a/src/objects/object.c +++ b/src/objects/object.c @@ -2,14 +2,16 @@ #include "pocketpy/pocketpy.h" #include -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); } \ No newline at end of file diff --git a/src/public/internal.c b/src/public/internal.c index c7be8853..8431634d 100644 --- a/src/public/internal.c +++ b/src/public/internal.c @@ -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); diff --git a/src/public/stack_ops.c b/src/public/stack_ops.c index 1c65000b..6a72e05f 100644 --- a/src/public/stack_ops.c +++ b/src/public/stack_ops.c @@ -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); } diff --git a/src/public/typecast.c b/src/public/typecast.c index a00fd491..69dbf690 100644 --- a/src/public/typecast.c +++ b/src/public/typecast.c @@ -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;