diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-02-19 16:42:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-02-19 16:42:07 +0300 |
commit | cdec2b3d15ab0448e4df70496285ed95681e5972 (patch) | |
tree | f6d2d49a28c45d035c0c047c9488d687a75d459b /source/gameengine/Expressions/PyObjectPlus.h | |
parent | c597863783e1001dca599e6dcbc28048f0ef4ce1 (diff) |
BGE Python API
Use 'const char *' rather then the C++ 'STR_String' type for the attribute identifier of python attributes.
Each attribute and method access from python was allocating and freeing the string.
A simple test with getting an attribute a loop shows this speeds up attribute lookups a bit over 2x.
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.h')
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index e0e2213d984..5092c8106ec 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -97,7 +97,7 @@ static inline void Py_Fatal(const char *M) { // to be properly passed up the hierarchy. #define _getattr_up(Parent) \ PyObject *rvalue = NULL; \ - if (attr=="__methods__") { \ + if (!strcmp(attr, "__methods__")) { \ PyObject *_attr_string = NULL; \ PyMethodDef *meth = Methods; \ rvalue = Parent::_getattr(attr); \ @@ -113,7 +113,7 @@ static inline void Py_Fatal(const char *M) { } \ } \ } else { \ - rvalue = Py_FindMethod(Methods, this, const_cast<char*>(attr.ReadPtr())); \ + rvalue = Py_FindMethod(Methods, this, attr); \ if (rvalue == NULL) { \ PyErr_Clear(); \ rvalue = Parent::_getattr(attr); \ @@ -348,23 +348,23 @@ public: // Py_DECREF(this); // }; // decref method - virtual PyObject *_getattr(const STR_String& attr); // _getattr method + virtual PyObject *_getattr(const char *attr); // _getattr method static PyObject *__getattr(PyObject * PyObj, char *attr) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->_getattr(STR_String(attr)); + return ((PyObjectPlus*) PyObj)->_getattr(attr); } - static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr); - static int _setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value); + static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr); + static int _setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value); - virtual int _delattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); // _setattr method + virtual int _delattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); // _setattr method static int __setattr(PyObject *PyObj, // This should be the entry in Type. char *attr, PyObject *value) { if (!value) return ((PyObjectPlus*) PyObj)->_delattr(attr); - return ((PyObjectPlus*) PyObj)->_setattr(STR_String(attr), value); + return ((PyObjectPlus*) PyObj)->_setattr(attr, value); } virtual PyObject *_repr(void); // _repr method |