[Bf-blender-cvs] [e03f335b1d8] master: Code cleanup: simplify switch statement, ensure we catch missing enums.

Brecht Van Lommel noreply at git.blender.org
Thu Feb 15 18:19:57 CET 2018


Commit: e03f335b1d81c3820e206849cb72860f7d2d2c39
Author: Brecht Van Lommel
Date:   Thu Feb 15 18:13:07 2018 +0100
Branches: master
https://developer.blender.org/rBe03f335b1d81c3820e206849cb72860f7d2d2c39

Code cleanup: simplify switch statement, ensure we catch missing enums.

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

M	intern/cycles/graph/node.cpp

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

diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp
index 19ed192652d..b16c6af5d0e 100644
--- a/intern/cycles/graph/node.cpp
+++ b/intern/cycles/graph/node.cpp
@@ -375,41 +375,38 @@ static bool is_value_equal(const Node *node, const Node *other, const SocketType
 
 bool Node::equals_value(const Node& other, const SocketType& socket) const
 {
-	if(socket.is_array()) {
-		switch(socket.type) {
-			case SocketType::BOOLEAN_ARRAY: return is_array_equal<bool>(this, &other, socket);
-			case SocketType::FLOAT_ARRAY: return is_array_equal<float>(this, &other, socket);
-			case SocketType::INT_ARRAY: return is_array_equal<int>(this, &other, socket);
-			case SocketType::COLOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
-			case SocketType::VECTOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
-			case SocketType::POINT_ARRAY: return is_array_equal<float3>(this, &other, socket);
-			case SocketType::NORMAL_ARRAY: return is_array_equal<float3>(this, &other, socket);
-			case SocketType::POINT2_ARRAY: return is_array_equal<float2>(this, &other, socket);
-			case SocketType::STRING_ARRAY: return is_array_equal<ustring>(this, &other, socket);
-			case SocketType::TRANSFORM_ARRAY: return is_array_equal<Transform>(this, &other, socket);
-			case SocketType::NODE_ARRAY: return is_array_equal<void*>(this, &other, socket);
-			default: assert(0); return true;
-		}
-	}
-	else {
-		switch(socket.type) {
-			case SocketType::BOOLEAN: return is_value_equal<bool>(this, &other, socket);
-			case SocketType::FLOAT: return is_value_equal<float>(this, &other, socket);
-			case SocketType::INT: return is_value_equal<int>(this, &other, socket);
-			case SocketType::UINT: return is_value_equal<uint>(this, &other, socket);
-			case SocketType::COLOR: return is_value_equal<float3>(this, &other, socket);
-			case SocketType::VECTOR: return is_value_equal<float3>(this, &other, socket);
-			case SocketType::POINT: return is_value_equal<float3>(this, &other, socket);
-			case SocketType::NORMAL: return is_value_equal<float3>(this, &other, socket);
-			case SocketType::POINT2: return is_value_equal<float2>(this, &other, socket);
-			case SocketType::CLOSURE: return true;
-			case SocketType::STRING: return is_value_equal<ustring>(this, &other, socket);
-			case SocketType::ENUM: return is_value_equal<int>(this, &other, socket);
-			case SocketType::TRANSFORM: return is_value_equal<Transform>(this, &other, socket);
-			case SocketType::NODE: return is_value_equal<void*>(this, &other, socket);
-			default: assert(0); return true;
-		}
+	switch(socket.type) {
+		case SocketType::BOOLEAN: return is_value_equal<bool>(this, &other, socket);
+		case SocketType::FLOAT: return is_value_equal<float>(this, &other, socket);
+		case SocketType::INT: return is_value_equal<int>(this, &other, socket);
+		case SocketType::UINT: return is_value_equal<uint>(this, &other, socket);
+		case SocketType::COLOR: return is_value_equal<float3>(this, &other, socket);
+		case SocketType::VECTOR: return is_value_equal<float3>(this, &other, socket);
+		case SocketType::POINT: return is_value_equal<float3>(this, &other, socket);
+		case SocketType::NORMAL: return is_value_equal<float3>(this, &other, socket);
+		case SocketType::POINT2: return is_value_equal<float2>(this, &other, socket);
+		case SocketType::CLOSURE: return true;
+		case SocketType::STRING: return is_value_equal<ustring>(this, &other, socket);
+		case SocketType::ENUM: return is_value_equal<int>(this, &other, socket);
+		case SocketType::TRANSFORM: return is_value_equal<Transform>(this, &other, socket);
+		case SocketType::NODE: return is_value_equal<void*>(this, &other, socket);
+
+		case SocketType::BOOLEAN_ARRAY: return is_array_equal<bool>(this, &other, socket);
+		case SocketType::FLOAT_ARRAY: return is_array_equal<float>(this, &other, socket);
+		case SocketType::INT_ARRAY: return is_array_equal<int>(this, &other, socket);
+		case SocketType::COLOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
+		case SocketType::VECTOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
+		case SocketType::POINT_ARRAY: return is_array_equal<float3>(this, &other, socket);
+		case SocketType::NORMAL_ARRAY: return is_array_equal<float3>(this, &other, socket);
+		case SocketType::POINT2_ARRAY: return is_array_equal<float2>(this, &other, socket);
+		case SocketType::STRING_ARRAY: return is_array_equal<ustring>(this, &other, socket);
+		case SocketType::TRANSFORM_ARRAY: return is_array_equal<Transform>(this, &other, socket);
+		case SocketType::NODE_ARRAY: return is_array_equal<void*>(this, &other, socket);
+
+		case SocketType::UNDEFINED: return true;
 	}
+
+	return true;
 }
 
 /* equals */
@@ -465,40 +462,35 @@ void Node::hash(MD5Hash& md5)
 	foreach(const SocketType& socket, type->inputs) {
 		md5.append(socket.name.string());
 
-		if(socket.is_array()) {
-			switch(socket.type) {
-				case SocketType::BOOLEAN_ARRAY: array_hash<bool>(this, socket, md5); break;
-				case SocketType::FLOAT_ARRAY: array_hash<float>(this, socket, md5); break;
-				case SocketType::INT_ARRAY: array_hash<int>(this, socket, md5); break;
-				case SocketType::COLOR_ARRAY: float3_array_hash(this, socket, md5); break;
-				case SocketType::VECTOR_ARRAY: float3_array_hash(this, socket, md5); break;
-				case SocketType::POINT_ARRAY: float3_array_hash(this, socket, md5); break;
-				case SocketType::NORMAL_ARRAY: float3_array_hash(this, socket, md5); break;
-				case SocketType::POINT2_ARRAY: array_hash<float2>(this, socket, md5); break;
-				case SocketType::STRING_ARRAY: array_hash<ustring>(this, socket, md5); break;
-				case SocketType::TRANSFORM_ARRAY: array_hash<Transform>(this, socket, md5); break;
-				case SocketType::NODE_ARRAY: array_hash<void*>(this, socket, md5); break;
-				default: assert(0); break;
-			}
-		}
-		else {
-			switch(socket.type) {
-				case SocketType::BOOLEAN: value_hash<bool>(this, socket, md5); break;
-				case SocketType::FLOAT: value_hash<float>(this, socket, md5); break;
-				case SocketType::INT: value_hash<int>(this, socket, md5); break;
-				case SocketType::UINT: value_hash<uint>(this, socket, md5); break;
-				case SocketType::COLOR: float3_hash(this, socket, md5); break;
-				case SocketType::VECTOR: float3_hash(this, socket, md5); break;
-				case SocketType::POINT: float3_hash(this, socket, md5); break;
-				case SocketType::NORMAL: float3_hash(this, socket, md5); break;
-				case SocketType::POINT2: value_hash<float2>(this, socket, md5); break;
-				case SocketType::CLOSURE: break;
-				case SocketType::STRING: value_hash<ustring>(this, socket, md5); break;
-				case SocketType::ENUM: value_hash<int>(this, socket, md5); break;
-				case SocketType::TRANSFORM: value_hash<Transform>(this, socket, md5); break;
-				case SocketType::NODE: value_hash<void*>(this, socket, md5); break;
-				default: assert(0); break;
-			}
+		switch(socket.type) {
+			case SocketType::BOOLEAN: value_hash<bool>(this, socket, md5); break;
+			case SocketType::FLOAT: value_hash<float>(this, socket, md5); break;
+			case SocketType::INT: value_hash<int>(this, socket, md5); break;
+			case SocketType::UINT: value_hash<uint>(this, socket, md5); break;
+			case SocketType::COLOR: float3_hash(this, socket, md5); break;
+			case SocketType::VECTOR: float3_hash(this, socket, md5); break;
+			case SocketType::POINT: float3_hash(this, socket, md5); break;
+			case SocketType::NORMAL: float3_hash(this, socket, md5); break;
+			case SocketType::POINT2: value_hash<float2>(this, socket, md5); break;
+			case SocketType::CLOSURE: break;
+			case SocketType::STRING: value_hash<ustring>(this, socket, md5); break;
+			case SocketType::ENUM: value_hash<int>(this, socket, md5); break;
+			case SocketType::TRANSFORM: value_hash<Transform>(this, socket, md5); break;
+			case SocketType::NODE: value_hash<void*>(this, socket, md5); break;
+
+			case SocketType::BOOLEAN_ARRAY: array_hash<bool>(this, socket, md5); break;
+			case SocketType::FLOAT_ARRAY: array_hash<float>(this, socket, md5); break;
+			case SocketType::INT_ARRAY: array_hash<int>(this, socket, md5); break;
+			case SocketType::COLOR_ARRAY: float3_array_hash(this, socket, md5); break;
+			case SocketType::VECTOR_ARRAY: float3_array_hash(this, socket, md5); break;
+			case SocketType::POINT_ARRAY: float3_array_hash(this, socket, md5); break;
+			case SocketType::NORMAL_ARRAY: float3_array_hash(this, socket, md5); break;
+			case SocketType::POINT2_ARRAY: array_hash<float2>(this, socket, md5); break;
+			case SocketType::STRING_ARRAY: array_hash<ustring>(this, socket, md5); break;
+			case SocketType::TRANSFORM_ARRAY: array_hash<Transform>(this, socket, md5); break;
+			case SocketType::NODE_ARRAY: array_hash<void*>(this, socket, md5); break;
+
+			case SocketType::UNDEFINED: break;
 		}
 	}
 }



More information about the Bf-blender-cvs mailing list