diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-10 17:45:27 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-10 17:45:27 +0300 |
commit | 2786b0bc9d64416817a25ab7e86f5b6cf5ef25b2 (patch) | |
tree | 0046d5e6c68cf773066164f0fb968dd6f52bfd2b /source/blender/blenkernel/intern/action.c | |
parent | e1a254d8dec4f43c73bb306834ba4badcf1f7e02 (diff) |
Optimize action constraint by avoid memory allocation
Diffstat (limited to 'source/blender/blenkernel/intern/action.c')
-rw-r--r-- | source/blender/blenkernel/intern/action.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 5b1bb8cb2bb..b969c9ec787 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -824,26 +824,35 @@ void BKE_pose_channels_free(bPose *pose) BKE_pose_channels_free_ex(pose, true); } +void BKE_pose_free_data_ex(bPose *pose, bool do_id_user) +{ + /* free pose-channels */ + BKE_pose_channels_free_ex(pose, do_id_user); + + /* free pose-groups */ + if (pose->agroups.first) + BLI_freelistN(&pose->agroups); + + /* free IK solver state */ + BIK_clear_data(pose); + + /* free IK solver param */ + if (pose->ikparam) + MEM_freeN(pose->ikparam); +} + +void BKE_pose_free_data(bPose *pose) +{ + BKE_pose_free_data_ex(pose, true); +} + /** * Removes and deallocates all data from a pose, and also frees the pose. */ void BKE_pose_free_ex(bPose *pose, bool do_id_user) { if (pose) { - /* free pose-channels */ - BKE_pose_channels_free_ex(pose, do_id_user); - - /* free pose-groups */ - if (pose->agroups.first) - BLI_freelistN(&pose->agroups); - - /* free IK solver state */ - BIK_clear_data(pose); - - /* free IK solver param */ - if (pose->ikparam) - MEM_freeN(pose->ikparam); - + BKE_pose_free_data_ex(pose, do_id_user); /* free pose */ MEM_freeN(pose); } @@ -1415,7 +1424,13 @@ void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, c workob->pose = pose; /* need to set pose too, since this is used for both types of Action Constraint */ if (pose) { - BKE_pose_channels_hash_make(pose); + /* This function is most likely to be used with a temporary pose with a single bone in there. + * For such cases it makes no sense to create hash since it'll only waste CPU ticks on memory + * allocation and also will make lookup slower. + */ + if (pose->chanbase.first != pose->chanbase.last) { + BKE_pose_channels_hash_make(pose); + } if (pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) { BKE_pose_update_constraint_flags(pose); } |