blueloveTH 8 месяцев назад
Родитель
Сommit
f9f74b7b12

+ 13 - 1
include/pocketpy/export.h

@@ -60,4 +60,16 @@
     #define PK_DEPRECATED __attribute__((deprecated))
 #else
     #define PK_DEPRECATED
-#endif
+#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

+ 0 - 1
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);
 

+ 4 - 4
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) {

+ 12 - 2
src/objects/namedict.c

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

+ 5 - 3
src/objects/object.c

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

+ 1 - 1
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);

+ 2 - 2
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);
 }

+ 1 - 1
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;