[Bf-blender-cvs] [6b1034d5203] master: Cleanup: Use a helper function for repetitive code

Hans Goudey noreply at git.blender.org
Tue May 11 02:17:22 CEST 2021


Commit: 6b1034d5203e1040bc9211cb765fa1cc3c05b7e2
Author: Hans Goudey
Date:   Mon May 10 19:17:15 2021 -0500
Branches: master
https://developer.blender.org/rB6b1034d5203e1040bc9211cb765fa1cc3c05b7e2

Cleanup: Use a helper function for repetitive code

Retrieving data from the component can be done in a separate function
to save some repetition.

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

M	source/blender/blenkernel/intern/geometry_component_curve.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 0490d577b88..503670861a5 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -136,6 +136,20 @@ int CurveComponent::attribute_domain_size(const AttributeDomain domain) const
   return 0;
 }
 
+static CurveEval *get_curve_from_component_for_write(GeometryComponent &component)
+{
+  BLI_assert(component.type() == GEO_COMPONENT_TYPE_CURVE);
+  CurveComponent &curve_component = static_cast<CurveComponent &>(component);
+  return curve_component.get_for_write();
+}
+
+static const CurveEval *get_curve_from_component_for_read(const GeometryComponent &component)
+{
+  BLI_assert(component.type() == GEO_COMPONENT_TYPE_CURVE);
+  const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
+  return curve_component.get_for_read();
+}
+
 namespace blender::bke {
 
 class BuiltinSplineAttributeProvider final : public BuiltinAttributeProvider {
@@ -164,8 +178,7 @@ class BuiltinSplineAttributeProvider final : public BuiltinAttributeProvider {
 
   GVArrayPtr try_get_for_read(const GeometryComponent &component) const final
   {
-    const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
-    const CurveEval *curve = curve_component.get_for_read();
+    const CurveEval *curve = get_curve_from_component_for_read(component);
     if (curve == nullptr) {
       return {};
     }
@@ -178,8 +191,7 @@ class BuiltinSplineAttributeProvider final : public BuiltinAttributeProvider {
     if (writable_ != Writable) {
       return {};
     }
-    CurveComponent &curve_component = static_cast<CurveComponent &>(component);
-    CurveEval *curve = curve_component.get_for_write();
+    CurveEval *curve = get_curve_from_component_for_write(component);
     if (curve == nullptr) {
       return {};
     }



More information about the Bf-blender-cvs mailing list