vala r1494 - in trunk: . vala



Author: juergbi
Date: Thu May 29 22:17:16 2008
New Revision: 1494
URL: http://svn.gnome.org/viewvc/vala?rev=1494&view=rev

Log:
2008-05-30  Juerg Billeter  <j bitron ch>

	* vala/valacodenode.vala:

	Use lazy initialization for error_types list in CodeNode class
	to improve performance


Modified:
   trunk/ChangeLog
   trunk/vala/valacodenode.vala

Modified: trunk/vala/valacodenode.vala
==============================================================================
--- trunk/vala/valacodenode.vala	(original)
+++ trunk/vala/valacodenode.vala	Thu May 29 22:17:16 2008
@@ -73,23 +73,33 @@
 	 * Specifies that this node or a child node may throw an exception.
 	 */
 	public bool tree_can_fail { 
-		get { return _error_types.size > 0; }
+		get { return _error_types != null && _error_types.size > 0; }
 	}
 
 	/**
 	 * Specifies the exceptions that can be thrown by this node or a child node
 	 */
 	public Gee.List<DataType> get_error_types () { 
-		return _error_types;
+		if (_error_types != null) {
+			return _error_types;
+		}
+		if (_empty_type_list == null) {
+			_empty_type_list = new ReadOnlyList<DataType> (new ArrayList<DataType> ());
+		}
+		return _empty_type_list;
 	}
 
-	private Gee.List<DataType> _error_types = new ArrayList<DataType> ();
+	private Gee.List<DataType> _error_types;
+	private static Gee.List<DataType> _empty_type_list;
 
 	/**
 	 * Adds an error type to the exceptions that can be thrown by this node
 	 * or a child node 
 	 */
 	public void add_error_type (DataType error_type) {
+		if (_error_types == null) {
+			_error_types = new ArrayList<DataType> ();
+		}
 		_error_types.add (error_type);
 		error_type.parent_node = this;
 	}
@@ -100,8 +110,7 @@
 	 */
 	public void add_error_types (Gee.List<DataType> error_types) {
 		foreach (DataType error_type in error_types) {
-			_error_types.add (error_type);
-			error_type.parent_node = this;
+			add_error_type (error_type);
 		}
 	}
 



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