From: Juerg Billeter Date: Thu, 29 May 2008 22:17:16 +0000 (+0000) Subject: Use lazy initialization for error_types list in CodeNode class to improve X-Git-Tag: VALA_0_3_3~64 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=387825ac17f24d2cd4d40706127ec733a9b6c685;p=platform%2Fupstream%2Fvala.git Use lazy initialization for error_types list in CodeNode class to improve 2008-05-30 Juerg Billeter * vala/valacodenode.vala: Use lazy initialization for error_types list in CodeNode class to improve performance svn path=/trunk/; revision=1494 --- diff --git a/ChangeLog b/ChangeLog index d02c72b..d432f73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-05-30 Jürg Billeter + + * vala/valacodenode.vala: + + Use lazy initialization for error_types list in CodeNode class + to improve performance + 2008-05-29 Jürg Billeter * vala/valablock.vala: diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index d924f4d..6adb08c 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 get_error_types () { - return _error_types; + if (_error_types != null) { + return _error_types; + } + if (_empty_type_list == null) { + _empty_type_list = new ReadOnlyList (new ArrayList ()); + } + return _empty_type_list; } - private Gee.List _error_types = new ArrayList (); + private Gee.List _error_types; + private static Gee.List _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 (); + } _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 error_types) { foreach (DataType error_type in error_types) { - _error_types.add (error_type); - error_type.parent_node = this; + add_error_type (error_type); } }