diff options
author | Juerg Billeter <j@bitron.ch> | 2008-05-29 22:17:16 +0000 |
---|---|---|
committer | Jürg Billeter <juergbi@src.gnome.org> | 2008-05-29 22:17:16 +0000 |
commit | 387825ac17f24d2cd4d40706127ec733a9b6c685 (patch) | |
tree | 3d5091a8abc21c11a52166f1accb7fc80db0cab4 /vala/valacodenode.vala | |
parent | 9a1d658bf2443da90e0d92ece53918d5905e2833 (diff) | |
download | vala-387825ac17f24d2cd4d40706127ec733a9b6c685.tar.gz |
Use lazy initialization for error_types list in CodeNode class to improve
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
Diffstat (limited to 'vala/valacodenode.vala')
-rw-r--r-- | vala/valacodenode.vala | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index d924f4d77..6adb08c06 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -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); } } |