Cleaning up the code.
authorMario de Sousa <msousa@fe.up.pt>
Wed, 18 Jul 2012 17:10:57 +0100
changeset 606 d2122a32ec86
parent 605 06caf4782e51
child 607 be9ba3531afb
Cleaning up the code.
stage3/datatype_functions.cc
stage3/datatype_functions.hh
--- a/stage3/datatype_functions.cc	Wed Jul 18 17:04:34 2012 +0100
+++ b/stage3/datatype_functions.cc	Wed Jul 18 17:10:57 2012 +0100
@@ -398,7 +398,7 @@
 /* Search for a datatype inside a candidate_datatypes list.
  * Returns: position of datatype in the list, or -1 if not found.
  */
-int search_in_candidate_datatype_list(symbol_c *datatype, std::vector <symbol_c *> candidate_datatypes) {
+int search_in_candidate_datatype_list(symbol_c *datatype, const std::vector <symbol_c *> &candidate_datatypes) {
 	if (NULL == datatype) 
 		return -1;
 
@@ -413,17 +413,12 @@
  * Returns: If successful it returns true, false otherwise.
  */
 bool remove_from_candidate_datatype_list(symbol_c *datatype, std::vector <symbol_c *> &candidate_datatypes) {
-	unsigned int ofs;
-	if (NULL == datatype)
+	int pos = search_in_candidate_datatype_list(datatype, candidate_datatypes);
+	if (pos < 0)
 		return false;
-	for(ofs = 0; ofs < candidate_datatypes.size(); ofs++)
-		if (is_type_equal(datatype, candidate_datatypes[ofs]))
-			break;
-	if (ofs <  candidate_datatypes.size()) {
-		candidate_datatypes.erase(candidate_datatypes.begin() + ofs);
-		return true;
-	}
-	return false;
+	
+	candidate_datatypes.erase(candidate_datatypes.begin() + pos);
+	return true;
 }
 
 
--- a/stage3/datatype_functions.hh	Wed Jul 18 17:04:34 2012 +0100
+++ b/stage3/datatype_functions.hh	Wed Jul 18 17:10:57 2012 +0100
@@ -142,7 +142,7 @@
 /* Search for a datatype inside a candidate_datatypes list.
  * Returns: position of datatype in the list, or -1 if not found.
  */
-int search_in_candidate_datatype_list(symbol_c *datatype, std::vector <symbol_c *> candidate_datatypes);
+int search_in_candidate_datatype_list(symbol_c *datatype, const std::vector <symbol_c *> &candidate_datatypes);
 
 /* Remove a datatype inside a candidate_datatypes list.
  * Returns: If successful it returns true, false otherwise.