From 0676a63a8d7f6b45d01d3ddf2f8d93018d8b15e6 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Fri, 30 May 2008 16:56:15 +0000 Subject: [PATCH] Use lazy initialization for type_argument_list in DataType class to 2008-05-30 Juerg Billeter * vala/valadatatype.vala: Use lazy initialization for type_argument_list in DataType class to improve performance svn path=/trunk/; revision=1498 --- ChangeLog | 7 +++++++ vala/valadatatype.vala | 28 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8d23a3..9e56da1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-05-30 Jürg Billeter + * vala/valadatatype.vala: + + Use lazy initialization for type_argument_list in DataType class + to improve performance + +2008-05-30 Jürg Billeter + * vala/valadynamicmethod.vala: * vala/valadynamicproperty.vala: * vala/valasymbol.vala: diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 3a13725..586173a 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -64,7 +64,8 @@ public abstract class Vala.DataType : CodeNode { */ public bool is_dynamic { get; set; } - private Gee.List type_argument_list = new ArrayList (); + private Gee.List type_argument_list; + private static Gee.List _empty_type_list; /** * Appends the specified type as generic type argument. @@ -72,6 +73,9 @@ public abstract class Vala.DataType : CodeNode { * @param arg a type reference */ public void add_type_argument (DataType arg) { + if (type_argument_list == null) { + type_argument_list = new ArrayList (); + } type_argument_list.add (arg); arg.parent_node = this; } @@ -82,18 +86,24 @@ public abstract class Vala.DataType : CodeNode { * @return type argument list */ public Gee.List get_type_arguments () { - return new ReadOnlyList (type_argument_list); + if (type_argument_list != null) { + return type_argument_list; + } + if (_empty_type_list == null) { + _empty_type_list = new ReadOnlyList (new ArrayList ()); + } + return _empty_type_list; } /** * Removes all generic type arguments. */ public void remove_all_type_arguments () { - type_argument_list.clear (); + type_argument_list = null; } public override void accept (CodeVisitor visitor) { - if (type_argument_list.size > 0) { + if (type_argument_list != null && type_argument_list.size > 0) { foreach (DataType type_arg in type_argument_list) { type_arg.accept (visitor); } @@ -276,10 +286,12 @@ public abstract class Vala.DataType : CodeNode { } public override void replace_type (DataType old_type, DataType new_type) { - for (int i = 0; i < type_argument_list.size; i++) { - if (type_argument_list[i] == old_type) { - type_argument_list[i] = new_type; - return; + if (type_argument_list != null) { + for (int i = 0; i < type_argument_list.size; i++) { + if (type_argument_list[i] == old_type) { + type_argument_list[i] = new_type; + return; + } } } } -- 2.7.4