Commit: 6a7ecec6e101faf3392e88dc07e2c1e2251ece1a
Author: Campbell Barton
Date:   Mon Jan 16 14:20:46 2023 +1100
Branches: master
https://developer.blender.org/rB6a7ecec6e101faf3392e88dc07e2c1e2251ece1a

Cleanup: avoid returning large structs from functions

Return BezTriple as a const pointer from utility functions
instead of by a value since it's a large struct.

===================================================================

M       source/blender/editors/animation/keyframes_general.c

===================================================================

diff --git a/source/blender/editors/animation/keyframes_general.c 
b/source/blender/editors/animation/keyframes_general.c
index c356f633053..49e40b39902 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -282,15 +282,15 @@ ListBase find_fcurve_segments(FCurve *fcu)
   return segments;
 }
 
-static BezTriple fcurve_segment_start_get(FCurve *fcu, int index)
+static const BezTriple *fcurve_segment_start_get(FCurve *fcu, int index)
 {
-  BezTriple start_bezt = index - 1 >= 0 ? fcu->bezt[index - 1] : 
fcu->bezt[index];
+  const BezTriple *start_bezt = index - 1 >= 0 ? &fcu->bezt[index - 1] : 
&fcu->bezt[index];
   return start_bezt;
 }
 
-static BezTriple fcurve_segment_end_get(FCurve *fcu, int index)
+static const BezTriple *fcurve_segment_end_get(FCurve *fcu, int index)
 {
-  BezTriple end_bezt = index < fcu->totvert ? fcu->bezt[index] : 
fcu->bezt[index - 1];
+  const BezTriple *end_bezt = index < fcu->totvert ? &fcu->bezt[index] : 
&fcu->bezt[index - 1];
   return end_bezt;
 }
 
@@ -299,7 +299,7 @@ static BezTriple fcurve_segment_end_get(FCurve *fcu, int 
index)
 void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, 
const float factor)
 {
   const float blend_factor = fabs(factor * 2 - 1);
-  BezTriple target_bezt;
+  const BezTriple *target_bezt;
   /* Find which key to blend towards. */
   if (factor < 0.5f) {
     target_bezt = fcurve_segment_start_get(fcu, segment->start_index);
@@ -309,7 +309,7 @@ void blend_to_neighbor_fcurve_segment(FCurve *fcu, 
FCurveSegment *segment, const
   }
   /* Blend each key individually. */
   for (int i = segment->start_index; i < segment->start_index + 
segment->length; i++) {
-    fcu->bezt[i].vec[1][1] = interpf(target_bezt.vec[1][1], 
fcu->bezt[i].vec[1][1], blend_factor);
+    fcu->bezt[i].vec[1][1] = interpf(target_bezt->vec[1][1], 
fcu->bezt[i].vec[1][1], blend_factor);
   }
 }
 
@@ -379,14 +379,14 @@ void blend_to_default_fcurve(PointerRNA *id_ptr, FCurve 
*fcu, const float factor
 
 void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float 
factor)
 {
-  const BezTriple left_key = fcurve_segment_start_get(fcu, 
segment->start_index);
-  const float left_x = left_key.vec[1][0];
-  const float left_y = left_key.vec[1][1];
+  const BezTriple *left_key = fcurve_segment_start_get(fcu, 
segment->start_index);
+  const float left_x = left_key->vec[1][0];
+  const float left_y = left_key->vec[1][1];
 
-  const BezTriple right_key = fcurve_segment_end_get(fcu, segment->start_index 
+ segment->length);
+  const BezTriple *right_key = fcurve_segment_end_get(fcu, 
segment->start_index + segment->length);
 
-  const float key_x_range = right_key.vec[1][0] - left_x;
-  const float key_y_range = right_key.vec[1][1] - left_y;
+  const float key_x_range = right_key->vec[1][0] - left_x;
+  const float key_y_range = right_key->vec[1][1] - left_y;
 
   /* Happens if there is only 1 key on the FCurve. Needs to be skipped because 
it
    * would be a divide by 0. */
@@ -419,11 +419,12 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment 
*segment, const float factor
 
 void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float 
factor)
 {
-  BezTriple left_bezt = fcurve_segment_start_get(fcu, segment->start_index);
-  BezTriple right_bezt = fcurve_segment_end_get(fcu, segment->start_index + 
segment->length);
+  const BezTriple *left_bezt = fcurve_segment_start_get(fcu, 
segment->start_index);
+  const BezTriple *right_bezt = fcurve_segment_end_get(fcu,
+                                                       segment->start_index + 
segment->length);
 
   for (int i = segment->start_index; i < segment->start_index + 
segment->length; i++) {
-    fcu->bezt[i].vec[1][1] = interpf(right_bezt.vec[1][1], 
left_bezt.vec[1][1], factor);
+    fcu->bezt[i].vec[1][1] = interpf(right_bezt->vec[1][1], 
left_bezt->vec[1][1], factor);
   }
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to