[vala] Improve performance of SemanticAnalyzer.is_type_accessible



commit f870d093e3ad54bd2cbbdc35f958b69a24b2d2eb
Author: Jürg Billeter <j bitron ch>
Date:   Sat Aug 21 12:07:28 2010 +0200

    Improve performance of SemanticAnalyzer.is_type_accessible

 vala/valaarraytype.vala        |    4 ++--
 vala/valadatatype.vala         |   13 ++++---------
 vala/valadelegatetype.vala     |    6 ++----
 vala/valapointertype.vala      |    4 ++--
 vala/valasemanticanalyzer.vala |   11 +----------
 vala/valasignaltype.vala       |    6 ++----
 vala/valasymbol.vala           |   12 ++++++++++++
 7 files changed, 25 insertions(+), 31 deletions(-)
---
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index ee57df5..9c651e7 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -232,8 +232,8 @@ public class Vala.ArrayType : ReferenceType {
 		}
 	}
 
-	public override List<Symbol> get_symbols () {
-		return element_type.get_symbols ();
+	public override bool is_accessible (Symbol sym) {
+		return element_type.is_accessible (sym);
 	}
 
 	public override bool check (SemanticAnalyzer analyzer) {
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 67bba32..aa838d1 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -435,17 +435,12 @@ public abstract class Vala.DataType : CodeNode {
 		return false;
 	}
 
-	/**
-	 * Returns a list of symbols that define this type.
-	 *
-	 * @return symbol list
-	 */
-	public virtual List<Symbol> get_symbols () {
-		var symbols = new ArrayList<Symbol> ();
+	// check whether this type is at least as accessible as the specified symbol
+	public virtual bool is_accessible (Symbol sym) {
 		if (data_type != null) {
-			symbols.add (data_type);
+			return data_type.is_accessible (sym);
 		}
-		return symbols;
+		return true;
 	}
 
 	public virtual Symbol? get_member (string member_name) {
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 5e49385..c904caf 100644
--- a/vala/valadelegatetype.vala
+++ b/vala/valadelegatetype.vala
@@ -93,10 +93,8 @@ public class Vala.DelegateType : DataType {
 		}
 	}
 
-	public override List<Symbol> get_symbols () {
-		var symbols = new ArrayList<Symbol> ();
-		symbols.add (delegate_symbol);
-		return symbols;
+	public override bool is_accessible (Symbol sym) {
+		return delegate_symbol.is_accessible (sym);
 	}
 
 	public override string? get_type_id () {
diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala
index f1b318d..9d11d8d 100644
--- a/vala/valapointertype.vala
+++ b/vala/valapointertype.vala
@@ -118,8 +118,8 @@ public class Vala.PointerType : DataType {
 		return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
 	}
 
-	public override List<Symbol> get_symbols () {
-		return base_type.get_symbols ();
+	public override bool is_accessible (Symbol sym) {
+		return base_type.is_accessible (sym);
 	}
 
 	public override string? get_type_id () {
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index e710912..db788fd 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -241,16 +241,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
 	// check whether type is at least as accessible as the specified symbol
 	public bool is_type_accessible (Symbol sym, DataType type) {
-		foreach (Symbol type_symbol in type.get_symbols ()) {
-			Scope method_scope = sym.get_top_accessible_scope ();
-			Scope type_scope = type_symbol.get_top_accessible_scope ();
-			if ((method_scope == null && type_scope != null)
-			    || (method_scope != null && !method_scope.is_subscope_of (type_scope))) {
-				return false;
-			}
-		}
-
-		return true;
+		return type.is_accessible (sym);
 	}
 
 	public DataType? get_value_type_for_symbol (Symbol sym, bool lvalue) {
diff --git a/vala/valasignaltype.vala b/vala/valasignaltype.vala
index 11a1109..6ab5568 100644
--- a/vala/valasignaltype.vala
+++ b/vala/valasignaltype.vala
@@ -113,9 +113,7 @@ public class Vala.SignalType : DataType {
 		return null;
 	}
 
-	public override List<Symbol> get_symbols () {
-		var symbols = new ArrayList<Symbol> ();
-		symbols.add (signal_symbol);
-		return symbols;
+	public override bool is_accessible (Symbol sym) {
+		return signal_symbol.is_accessible (sym);
 	}
 }
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index a46112f..9bea678 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -497,6 +497,18 @@ public abstract class Vala.Symbol : CodeNode {
 		return null;
 	}
 
+	// check whether this symbol is at least as accessible as the specified symbol
+	public  bool is_accessible (Symbol sym) {
+		Scope sym_scope = sym.get_top_accessible_scope ();
+		Scope this_scope = this.get_top_accessible_scope ();
+		if ((sym_scope == null && this_scope != null)
+		    || (sym_scope != null && !sym_scope.is_subscope_of (this_scope))) {
+			return false;
+		}
+
+		return true;
+	}
+
 	public virtual void add_namespace (Namespace ns) {
 		Report.error (ns.source_reference, "unexpected declaration");
 	}



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