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.
This commit is contained in:
@@ -142,23 +142,21 @@ PyParentObject KX_PhysicsObjectWrapper::Parents[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
PyObject* KX_PhysicsObjectWrapper::_getattr(const STR_String& attr)
|
||||
PyObject* KX_PhysicsObjectWrapper::_getattr(const char *attr)
|
||||
{
|
||||
_getattr_up(PyObjectPlus);
|
||||
}
|
||||
|
||||
|
||||
int KX_PhysicsObjectWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
|
||||
int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj)
|
||||
{
|
||||
PyTypeObject* type = pyobj->ob_type;
|
||||
int result = 1;
|
||||
|
||||
|
||||
if (type == &PyInt_Type)
|
||||
if (PyInt_Check(pyobj))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (type == &PyString_Type)
|
||||
if (PyString_Check(pyobj))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user