[Bf-blender-cvs] [74a566d211e] master: Cleanup: Return early in null check

Hans Goudey noreply at git.blender.org
Thu Dec 9 21:34:25 CET 2021


Commit: 74a566d211e011abb10ba3d1878287341f6f177b
Author: Hans Goudey
Date:   Thu Dec 9 14:34:15 2021 -0600
Branches: master
https://developer.blender.org/rB74a566d211e011abb10ba3d1878287341f6f177b

Cleanup: Return early in null check

I'm planning to make these functions slightly more complicated,
and it makes sense to return early when checking one of the parameters
for null anyway.

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

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

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

diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 3e812a7e3c5..214d88d1a63 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -351,44 +351,44 @@ void GeometrySet::replace_mesh(Mesh *mesh, GeometryOwnershipType ownership)
 {
   if (mesh == nullptr) {
     this->remove<MeshComponent>();
+    return;
   }
-  else {
-    MeshComponent &component = this->get_component_for_write<MeshComponent>();
-    component.replace(mesh, ownership);
-  }
+
+  MeshComponent &component = this->get_component_for_write<MeshComponent>();
+  component.replace(mesh, ownership);
 }
 
 void GeometrySet::replace_curve(CurveEval *curve, GeometryOwnershipType ownership)
 {
   if (curve == nullptr) {
     this->remove<CurveComponent>();
+    return;
   }
-  else {
-    CurveComponent &component = this->get_component_for_write<CurveComponent>();
-    component.replace(curve, ownership);
-  }
+
+  CurveComponent &component = this->get_component_for_write<CurveComponent>();
+  component.replace(curve, ownership);
 }
 
 void GeometrySet::replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership)
 {
   if (pointcloud == nullptr) {
     this->remove<PointCloudComponent>();
+    return;
   }
-  else {
-    PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>();
-    component.replace(pointcloud, ownership);
-  }
+
+  PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>();
+  component.replace(pointcloud, ownership);
 }
 
 void GeometrySet::replace_volume(Volume *volume, GeometryOwnershipType ownership)
 {
   if (volume == nullptr) {
     this->remove<VolumeComponent>();
+    return;
   }
-  else {
-    VolumeComponent &component = this->get_component_for_write<VolumeComponent>();
-    component.replace(volume, ownership);
-  }
+
+  VolumeComponent &component = this->get_component_for_write<VolumeComponent>();
+  component.replace(volume, ownership);
 }
 
 Mesh *GeometrySet::get_mesh_for_write()



More information about the Bf-blender-cvs mailing list