Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-02-19 16:42:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-02-19 16:42:07 +0300
commitcdec2b3d15ab0448e4df70496285ed95681e5972 (patch)
treef6d2d49a28c45d035c0c047c9488d687a75d459b /source/gameengine/Expressions
parentc597863783e1001dca599e6dcbc28048f0ef4ce1 (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')
-rw-r--r--source/gameengine/Expressions/ListValue.cpp2
-rw-r--r--source/gameengine/Expressions/ListValue.h2
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp18
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h18
-rw-r--r--source/gameengine/Expressions/Value.cpp15
-rw-r--r--source/gameengine/Expressions/Value.h6
6 files changed, 31 insertions, 30 deletions
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index b7236afdee4..3cf22bdc9bd 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -234,7 +234,7 @@ PyMethodDef CListValue::Methods[] = {
-PyObject* CListValue::_getattr(const STR_String& attr) {
+PyObject* CListValue::_getattr(const char *attr) {
_getattr_up(CValue);
}
diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h
index 431f8f558a9..8c0bd767938 100644
--- a/source/gameengine/Expressions/ListValue.h
+++ b/source/gameengine/Expressions/ListValue.h
@@ -59,7 +59,7 @@ public:
bool CheckEqual(CValue* first,CValue* second);
- virtual PyObject* _getattr(const STR_String& attr);
+ virtual PyObject* _getattr(const char *attr);
KX_PYMETHOD(CListValue,append);
KX_PYMETHOD(CListValue,reverse);
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index 19f458b69a6..16184b7c5f2 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -106,24 +106,24 @@ PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL};
/*------------------------------
* PyObjectPlus attributes -- attributes
------------------------------*/
-PyObject *PyObjectPlus::_getattr(const STR_String& attr)
+PyObject *PyObjectPlus::_getattr(const char *attr)
{
- if (attr == "__doc__" && GetType()->tp_doc)
+ if (!strcmp(attr, "__doc__") && GetType()->tp_doc)
return PyString_FromString(GetType()->tp_doc);
//if (streq(attr, "type"))
// return Py_BuildValue("s", (*(GetParents()))->tp_name);
- return Py_FindMethod(Methods, this, const_cast<char *>(attr.ReadPtr()));
+ return Py_FindMethod(Methods, this, attr);
}
-int PyObjectPlus::_delattr(const STR_String& attr)
+int PyObjectPlus::_delattr(const char *attr)
{
PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted");
return 1;
}
-int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value)
+int PyObjectPlus::_setattr(const char *attr, PyObject *value)
{
//return PyObject::_setattr(attr,value);
//cerr << "Unknown attribute" << endl;
@@ -131,12 +131,12 @@ int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value)
return 1;
}
-PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr)
+PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr)
{
const PyAttributeDef *attrdef;
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
{
- if (attr == attrdef->m_name)
+ if (!strcmp(attr, attrdef->m_name))
{
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
{
@@ -238,7 +238,7 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel
return NULL;
}
-int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value)
+int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value)
{
const PyAttributeDef *attrdef;
void *undoBuffer = NULL;
@@ -247,7 +247,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
{
- if (attr == attrdef->m_name)
+ if (!strcmp(attr, attrdef->m_name))
{
if (attrdef->m_access == KX_PYATTRIBUTE_RO ||
attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
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
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index f2b5569c76e..f30dd1a71ed 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -674,9 +674,9 @@ static PyMethodDef CValueMethods[] =
};
-PyObject* CValue::_getattr(const STR_String& attr)
+PyObject* CValue::_getattr(const char *attr)
{
- CValue* resultattr = FindIdentifier(attr);
+ CValue* resultattr = FindIdentifier(STR_String(attr));
STR_String text;
if (resultattr)
{
@@ -761,26 +761,27 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
}
-int CValue::_delattr(const STR_String& attr)
+int CValue::_delattr(const char *attr)
{
- if (!RemoveProperty(attr)) /* sets error */
+ if (!RemoveProperty(STR_String(attr))) /* sets error */
return 1;
return 0;
}
-int CValue::_setattr(const STR_String& attr,PyObject* pyobj)
+int CValue::_setattr(const char *attr,PyObject* pyobj)
{
CValue* vallie = ConvertPythonToValue(pyobj);
if (vallie)
{
- CValue* oldprop = GetProperty(attr);
+ STR_String attr_str = attr;
+ CValue* oldprop = GetProperty(attr_str);
if (oldprop)
{
oldprop->SetValue(vallie);
} else
{
- SetProperty(attr,vallie);
+ SetProperty(attr_str, vallie);
}
vallie->Release();
} else
diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h
index 56a4991af27..854334b892b 100644
--- a/source/gameengine/Expressions/Value.h
+++ b/source/gameengine/Expressions/Value.h
@@ -223,7 +223,7 @@ public:
- virtual PyObject* _getattr(const STR_String& attr);
+ virtual PyObject* _getattr(const char *attr);
void SpecialRelease()
{
@@ -250,8 +250,8 @@ public:
virtual CValue* ConvertPythonToValue(PyObject* pyobj);
- virtual int _delattr(const STR_String& attr);
- virtual int _setattr(const STR_String& attr,PyObject* value);
+ virtual int _delattr(const char *attr);
+ virtual int _setattr(const char *attr, PyObject* value);
virtual PyObject* ConvertKeysToPython( void );