[vala/switch-to-gir: 7/34] girparser: Stop parsing if the context already has the provided package.



commit b55f764e9dffbdfd80e296775df2ac3992222ae3
Author: Luca Bruno <lethalman88 gmail com>
Date:   Mon Aug 23 21:29:42 2010 +0200

    girparser: Stop parsing if the context already has the provided package.

 compiler/valacompiler.vala |    6 ------
 vala/valagirparser.vala    |   32 ++++++++++----------------------
 2 files changed, 10 insertions(+), 28 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index f3a445e..e0fdd53 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -312,12 +312,6 @@ class Vala.Compiler {
 		var gir_parser = new GirParser ();
 		gir_parser.parse (context);
 
-		if (gir_parser.get_package_names != null) {
-			foreach (var pkg in gir_parser.get_package_names ()) {
-				context.add_package (pkg);
-			}
-		}
-
 		if (context.report.get_errors () > 0 || (fatal_warnings && context.report.get_warnings () > 0)) {
 			return quit ();
 		}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 871f4cb..a258d84 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -37,7 +37,6 @@ public class Vala.GirParser : CodeVisitor {
 	MarkupTokenType current_token;
 
 	string[] cheader_filenames;
-	string[] package_names;
 
 	HashMap<string,string> attributes_map = new HashMap<string,string> (str_hash, str_equal);
 
@@ -143,7 +142,13 @@ public class Vala.GirParser : CodeVisitor {
 			} else if (reader.name == "include") {
 				parse_include ();
 			} else if (reader.name == "package") {
-				parse_package ();
+				var pkg = parse_package ();
+				if (context.has_package (pkg)) {
+					// package already provided elsewhere, stop parsing this GIR
+					return;
+				} else {
+					context.add_package (pkg);
+				}
 			} else if (reader.name == "c:include") {
 				parse_c_include ();
 			} else {
@@ -161,11 +166,12 @@ public class Vala.GirParser : CodeVisitor {
 		end_element ("include");
 	}
 
-	void parse_package () {
+	string parse_package () {
 		start_element ("package");
-		add_package_name (reader.get_attribute ("name"));
+		var pkg = reader.get_attribute ("name");
 		next ();
 		end_element ("package");
+		return pkg;
 	}
 
 	void parse_c_include () {
@@ -1378,23 +1384,5 @@ public class Vala.GirParser : CodeVisitor {
 			Report.error (null, "Metadata file `%s' not found".printf (metadata_filename));
 		}
 	}
-
-	void add_package_name (string name) {
-		if (package_names == null) {
-			package_names = new string[0];
-		}
-
-		foreach (var existing in package_names) {
-			if (name == existing) {
-				return;
-			}
-		}
-
-		package_names += name;
-	}
-
-	public string[]? get_package_names () {
-		return package_names;
-	}
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]