From: Juerg Billeter Date: Sun, 22 Jul 2007 18:13:55 +0000 (+0000) Subject: use lazy initialization for array_types hash table X-Git-Tag: VALA_0_1_2~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eac4ed4b4678d3d9d8a7bc3ea2382c4cd4bd220a;p=thirdparty%2Fvala.git use lazy initialization for array_types hash table 2007-07-22 Juerg Billeter * vala/valadatatype.vala: use lazy initialization for array_types hash table svn path=/trunk/; revision=369 --- diff --git a/ChangeLog b/ChangeLog index e5ba85afe..a53e18070 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-22 Jürg Billeter + + * vala/valadatatype.vala: use lazy initialization for array_types + hash table + 2007-07-22 Jürg Billeter * vala/valainterface.vala, vala/valainterfacewriter.vala: support diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 85299666a..57249d892 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -41,8 +41,7 @@ public abstract class Vala.DataType : Symbol { private Pointer pointer_type; /* holds the array types of this type; each rank is a separate one */ - /* FIXME: uses string because int does not work as key yet */ - private HashTable array_types = new HashTable.full (str_hash, str_equal, g_free, g_object_unref); + private HashTable array_types; /** * Returns the name of this data type as it is used in C code. @@ -235,9 +234,17 @@ public abstract class Vala.DataType : Symbol { * @return array type for this data type */ public Array! get_array (int rank) { - Array array_type = (Array) array_types.lookup (rank.to_string ()); - + Array array_type = null; + + if (array_types != null) { + array_type = array_types.lookup (rank); + } + if (array_type == null) { + if (array_types == null) { + array_types = new HashTable.full (direct_hash, direct_equal, null, g_object_unref); + } + var new_array_type = new Array (this, rank, source_reference); parent_symbol.scope.add (new_array_type.name, new_array_type); @@ -249,7 +256,7 @@ public abstract class Vala.DataType : Symbol { /* link the array type to the same source as the container type */ new_array_type.source_reference = this.source_reference; - array_types.insert (rank.to_string (), new_array_type); + array_types.insert (rank, new_array_type); array_type = new_array_type; }