diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-08 13:36:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-08 13:36:46 +0300 |
commit | 0391b1ab780b34a149d3c4181d0fe676ef55199e (patch) | |
tree | fcc5611cd83129f9c475591d47fb47cea84dc491 /source/blender/python | |
parent | 445d077cf4ecc84b5d5cf422bfb2040186d60164 (diff) |
compile python driver expressions for faster re-evaluation.
approx 15-25x speedup
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index a055060ed07..6a94443dd8b 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -134,7 +134,7 @@ extern "C" { // void BPY_scripts_clear_pyobjects( void ); // // void error_pyscript( void ); -// void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */ + void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */ void BPY_set_context(struct bContext *C); /* void BPY_Err_Handle(struct Text *text); */ /* int BPY_spacetext_is_pywin(struct SpaceText *st); */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index d4d0cbf602f..af1d522600a 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -549,7 +549,9 @@ int BPY_run_script_space_listener(bContext *C, SpaceScript * sc) void BPY_DECREF(void *pyob_ptr) { + PyGILState_STATE gilstate = PyGILState_Ensure(); Py_DECREF((PyObject *)pyob_ptr); + PyGILState_Release(gilstate); } #if 0 @@ -721,7 +723,7 @@ static float pydriver_error(ChannelDriver *driver) float BPY_pydriver_eval (ChannelDriver *driver) { PyObject *driver_vars=NULL; - PyObject *retval; + PyObject *retval= NULL; PyGILState_STATE gilstate; DriverTarget *dtar; @@ -772,10 +774,20 @@ float BPY_pydriver_eval (ChannelDriver *driver) BPy_errors_to_report(NULL); // TODO - reports } } - + +#if 0 // slow /* execute expression to get a value */ retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); - +#else + if(driver->flag & DRIVER_FLAG_RECOMPILE || driver->expr_comp==NULL) { + Py_XDECREF(driver->expr_comp); + driver->expr_comp= Py_CompileString(expr, "<bpy driver>", Py_eval_input); + driver->flag &= ~DRIVER_FLAG_RECOMPILE; + } + if(driver->expr_comp) + retval= PyEval_EvalCode(driver->expr_comp, bpy_pydriver_Dict, driver_vars); +#endif + /* decref the driver vars first... */ Py_DECREF(driver_vars); |