From: Jürg Billeter Date: Sat, 21 Aug 2010 09:55:35 +0000 (+0200) Subject: Create array lists in Method class only on demand X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f9b3095514712c7d5acb95555b70fcbf681fb82;p=thirdparty%2Fvala.git Create array lists in Method class only on demand --- diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 29f30abf6..5d3cbeb13 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -28,7 +28,7 @@ using GLib; * Represents a type or namespace method. */ public class Vala.Method : Symbol { - List type_parameters = new ArrayList (); + List type_parameters; public const string DEFAULT_SENTINEL = "NULL"; @@ -238,8 +238,8 @@ public class Vala.Method : Symbol { private string finish_name; private string _vfunc_name; private string _sentinel; - private List preconditions = new ArrayList (); - private List postconditions = new ArrayList (); + private List preconditions; + private List postconditions; private DataType _return_type; private Block _body; @@ -252,6 +252,9 @@ public class Vala.Method : Symbol { // only valid for closures List captured_variables; + static List _empty_expression_list; + static List _empty_type_parameter_list; + /** * Creates a new method. * @@ -327,12 +330,16 @@ public class Vala.Method : Symbol { result_var.accept (visitor); } - foreach (Expression precondition in preconditions) { - precondition.accept (visitor); + if (preconditions != null) { + foreach (Expression precondition in preconditions) { + precondition.accept (visitor); + } } - foreach (Expression postcondition in postconditions) { - postcondition.accept (visitor); + if (postconditions != null) { + foreach (Expression postcondition in postconditions) { + postcondition.accept (visitor); + } } if (body != null) { @@ -590,6 +597,9 @@ public class Vala.Method : Symbol { * @param p a type parameter */ public void add_type_parameter (TypeParameter p) { + if (type_parameters == null) { + type_parameters = new ArrayList (); + } type_parameters.add (p); scope.add (p.name, p); } @@ -600,10 +610,20 @@ public class Vala.Method : Symbol { * @return list of type parameters */ public List get_type_parameters () { - return type_parameters; + if (type_parameters != null) { + return type_parameters; + } + if (_empty_type_parameter_list == null) { + _empty_type_parameter_list = new ArrayList (); + } + return _empty_type_parameter_list; } public int get_type_parameter_index (string name) { + if (type_parameters == null) { + return -1; + } + int i = 0; foreach (TypeParameter parameter in type_parameters) { if (parameter.name == name) { @@ -620,6 +640,9 @@ public class Vala.Method : Symbol { * @param precondition a boolean precondition expression */ public void add_precondition (Expression precondition) { + if (preconditions == null) { + preconditions = new ArrayList (); + } preconditions.add (precondition); precondition.parent_node = this; } @@ -630,7 +653,13 @@ public class Vala.Method : Symbol { * @return list of preconditions */ public List get_preconditions () { - return preconditions; + if (preconditions != null) { + return preconditions; + } + if (_empty_expression_list == null) { + _empty_expression_list = new ArrayList (); + } + return _empty_expression_list; } /** @@ -639,6 +668,9 @@ public class Vala.Method : Symbol { * @param postcondition a boolean postcondition expression */ public void add_postcondition (Expression postcondition) { + if (postconditions == null) { + postconditions = new ArrayList (); + } postconditions.add (postcondition); postcondition.parent_node = this; } @@ -649,7 +681,13 @@ public class Vala.Method : Symbol { * @return list of postconditions */ public List get_postconditions () { - return postconditions; + if (postconditions != null) { + return postconditions; + } + if (_empty_expression_list == null) { + _empty_expression_list = new ArrayList (); + } + return _empty_expression_list; } public override void replace_type (DataType old_type, DataType new_type) { @@ -853,12 +891,16 @@ public class Vala.Method : Symbol { result_var.check (analyzer); } - foreach (Expression precondition in preconditions) { - precondition.check (analyzer); + if (preconditions != null) { + foreach (Expression precondition in preconditions) { + precondition.check (analyzer); + } } - foreach (Expression postcondition in postconditions) { - postcondition.check (analyzer); + if (postconditions != null) { + foreach (Expression postcondition in postconditions) { + postcondition.check (analyzer); + } } if (body != null) {