Use lazy initialization for error_types list in CodeNode class to improve
authorJuerg Billeter <j@bitron.ch>
Thu, 29 May 2008 22:17:16 +0000 (22:17 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 29 May 2008 22:17:16 +0000 (22:17 +0000)
2008-05-30  Juerg Billeter  <j@bitron.ch>

* vala/valacodenode.vala:

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

svn path=/trunk/; revision=1494

ChangeLog
vala/valacodenode.vala

index d02c72b..d432f73 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-05-30  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodenode.vala:
+
+       Use lazy initialization for error_types list in CodeNode class
+       to improve performance
+
 2008-05-29  Jürg Billeter  <j@bitron.ch>
 
        * vala/valablock.vala:
index d924f4d..6adb08c 100644 (file)
@@ -73,23 +73,33 @@ public abstract class Vala.CodeNode : Object {
         * 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 abstract class Vala.CodeNode : Object {
         */
        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);
                }
        }