From bbe42c9fa216335dd56424014bda666a5d6717de Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 31 Oct 2016 06:21:50 +0100 Subject: name_table: auto-initialize. --- src/name_table.adb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/name_table.adb') diff --git a/src/name_table.adb b/src/name_table.adb index b4bc24ca4..3d0010bce 100644 --- a/src/name_table.adb +++ b/src/name_table.adb @@ -1,5 +1,5 @@ -- Name table. --- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold +-- Copyright (C) 2002 - 2016 Tristan Gingold -- -- GHDL is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free @@ -52,6 +52,9 @@ package body Name_Table is type Hash_Array is array (Hash_Value_Type range <>) of Name_Id; type Hash_Array_Acc is access Hash_Array; + procedure Deallocate is new Ada.Unchecked_Deallocation + (Hash_Array, Hash_Array_Acc); + -- Hash table. Lower bound is always 0, upper bound is always -- Hash_Table_Size - 1. Hash_Table: Hash_Array_Acc; @@ -107,7 +110,7 @@ package body Name_Table is Strings_Table.Append (NUL); - -- Reserve entry 0. + -- Reserve entry 0 for Null_Identifier. Strings_Table.Append (NUL); Names_Table.Append ((Hash => 0, Name => Strings_Table.Last, @@ -128,10 +131,19 @@ package body Name_Table is Append_Terminator; + -- Allocate the Hash_Table. + Hash_Table_Size := 1024; Hash_Table := new Hash_Array'(0 .. Hash_Table_Size - 1 => Null_Identifier); end Initialize; + procedure Finalize is + begin + Strings_Table.Free; + Names_Table.Free; + Deallocate (Hash_Table); + end Finalize; + -- Compute the hash value of a string. In case of algorithm change, check -- the performance using Disp_Stats. function Hash return Hash_Value_Type @@ -238,9 +250,6 @@ package body Name_Table is -- Expand the hash table (double the size). procedure Expand is - procedure Deallocate is new Ada.Unchecked_Deallocation - (Hash_Array, Hash_Array_Acc); - Old_Hash_Table : Hash_Array_Acc; Id : Name_Id; begin @@ -309,8 +318,6 @@ package body Name_Table is Hash_Table (Hash_Index) := Res; Append_Terminator; - --Put_Line ("created"); - return Res; end Get_Identifier; @@ -442,4 +449,6 @@ package body Name_Table is end loop; end; end Disp_Stats; +begin + Initialize; end Name_Table; -- cgit v1.2.3