Browse Source

slightly improved performance of are_connected by requiring 2 less variables and avoiding string comparison

tpinna 10 years ago
parent
commit
2eb2601820
1 changed files with 5 additions and 12 deletions
  1. 5 12
      integration/code/pn_interface.alc

+ 5 - 12
integration/code/pn_interface.alc

@@ -80,7 +80,7 @@ Element pivots
 
 Boolean function node_match(transf_model : Element, transf_elem : Element, host_model : Element, host_elem : Element):
 
-	//type equality
+	//type "equality"
 	String type1
 	type1 = getTypeName(transf_model, transf_elem)
 	String type2
@@ -105,14 +105,10 @@ Boolean function node_match(transf_model : Element, transf_elem : Element, host_
 	return False
 
 Integer function are_connected(model: Element, el1:Element, el2:Element):
-	String el1_mmt
-	String el2_mmt
-	el1_mmt = getMetaTypeName(model, el1)
-	el2_mmt = getMetaTypeName(model, el2)
-	if ( el1_mmt == "Class" ):
-		if(el2_mmt == "Class"):
+	if ( bool_not(is_edge(el1)) ):
+		if(bool_not(is_edge(el2))):
 			return 0 //not connected, no edge inbetween
-		elif(el2_mmt == "l5"):
+		elif(is_edge(el2)):
 			if( element_eq(read_edge_src(el2) , el1)):
 				return 1 //outgoing
 			elif( element_eq(read_edge_dst(el2) , el1)):
@@ -122,16 +118,13 @@ Integer function are_connected(model: Element, el1:Element, el2:Element):
 		else:
 			log("is_connected_to: unsupported type for second element")
 			log(string_join("type = ", el2_mmt))
-	elif (el1_mmt == "l5"):
+	else:
 		if( element_eq(read_edge_src(el1) , el2)):
 			return 2 //incoming
 		elif( element_eq(read_edge_dst(el1) , el2)):
 			return 1 //outgoing
 		else:
 			return 0 //edge is not connected
-	else:
-		log("is_connected_to: unsupported type for first element")
-		log(string_join("type = ", el1_mmt))
 	return 0 // if the function doesn't support it, assume disconnected