Commit de972f9d by Pascal Obry Committed by Arnaud Charlet

g-dynhta.ads, [...] (Reset): Free the table itself after releasing the items.

2005-06-14  Pascal Obry  <obry@adacore.com>

	* g-dynhta.ads, g-dynhta.adb (Reset): Free the table itself after
	releasing the items.

From-SVN: r101041
parent df957272
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- -- -- --
-- GNAT RUNTIME COMPONENTS -- -- GNAT RUN-TIME COMPONENTS --
-- -- -- --
-- G N A T . D Y N A M I C _ H T A B L E S -- -- G N A T . D Y N A M I C _ H T A B L E S --
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2002-2004 Ada Core Technologies, Inc. -- -- Copyright (C) 2002-2005 AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation; with Ada.Unchecked_Deallocation;
package body GNAT.Dynamic_HTables is package body GNAT.Dynamic_HTables is
------------------- -------------------
...@@ -179,6 +180,9 @@ package body GNAT.Dynamic_HTables is ...@@ -179,6 +180,9 @@ package body GNAT.Dynamic_HTables is
----------- -----------
procedure Reset (T : in out Instance) is procedure Reset (T : in out Instance) is
procedure Free is
new Ada.Unchecked_Deallocation (Instance_Data, Instance);
begin begin
if T = null then if T = null then
return; return;
...@@ -187,6 +191,8 @@ package body GNAT.Dynamic_HTables is ...@@ -187,6 +191,8 @@ package body GNAT.Dynamic_HTables is
for J in T.Table'Range loop for J in T.Table'Range loop
T.Table (J) := Null_Ptr; T.Table (J) := Null_Ptr;
end loop; end loop;
Free (T);
end Reset; end Reset;
--------- ---------
...@@ -205,6 +211,7 @@ package body GNAT.Dynamic_HTables is ...@@ -205,6 +211,7 @@ package body GNAT.Dynamic_HTables is
Set_Next (E, T.Table (Index)); Set_Next (E, T.Table (Index));
T.Table (Index) := E; T.Table (Index) := E;
end Set; end Set;
end Static_HTable; end Static_HTable;
------------------- -------------------
...@@ -264,7 +271,6 @@ package body GNAT.Dynamic_HTables is ...@@ -264,7 +271,6 @@ package body GNAT.Dynamic_HTables is
function Get_Next (T : Instance) return Element is function Get_Next (T : Instance) return Element is
Tmp : constant Elmt_Ptr := Tab.Get_Next (Tab.Instance (T)); Tmp : constant Elmt_Ptr := Tab.Get_Next (Tab.Instance (T));
begin begin
if Tmp = null then if Tmp = null then
return No_Element; return No_Element;
...@@ -322,7 +328,6 @@ package body GNAT.Dynamic_HTables is ...@@ -322,7 +328,6 @@ package body GNAT.Dynamic_HTables is
procedure Set (T : in out Instance; K : Key; E : Element) is procedure Set (T : in out Instance; K : Key; E : Element) is
Tmp : constant Elmt_Ptr := Tab.Get (Tab.Instance (T), K); Tmp : constant Elmt_Ptr := Tab.Get (Tab.Instance (T), K);
begin begin
if Tmp = null then if Tmp = null then
Tab.Set (Tab.Instance (T), new Element_Wrapper'(K, E, null)); Tab.Set (Tab.Instance (T), new Element_Wrapper'(K, E, null));
...@@ -339,6 +344,7 @@ package body GNAT.Dynamic_HTables is ...@@ -339,6 +344,7 @@ package body GNAT.Dynamic_HTables is
begin begin
E.Next := Next; E.Next := Next;
end Set_Next; end Set_Next;
end Simple_HTable; end Simple_HTable;
end GNAT.Dynamic_HTables; end GNAT.Dynamic_HTables;
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- -- -- --
-- GNAT RUNTIME COMPONENTS -- -- GNAT RUN-TIME COMPONENTS --
-- -- -- --
-- G N A T . D Y N A M I C _ H T A B L E S -- -- G N A T . D Y N A M I C _ H T A B L E S --
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1995-2003 Ada Core Technologies, Inc. -- -- Copyright (C) 1995-2005 AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -103,13 +103,13 @@ package GNAT.Dynamic_HTables is ...@@ -103,13 +103,13 @@ package GNAT.Dynamic_HTables is
Nil : constant Instance; Nil : constant Instance;
procedure Reset (T : in out Instance); procedure Reset (T : in out Instance);
-- Resets the hash table by setting all its elements to Null_Ptr. The -- Resets the hash table by releasing all memory associated with
-- effect is to clear the hash table so that it can be reused. For the -- it. The hash table can safely be reused after this call. For the
-- most common case where Elmt_Ptr is an access type, and Null_Ptr is -- most common case where Elmt_Ptr is an access type, and Null_Ptr is
-- null, this is only needed if the same table is reused in a new -- null, this is only needed if the same table is reused in a new
-- context. If Elmt_Ptr is other than an access type, or Null_Ptr is -- context. If Elmt_Ptr is other than an access type, or Null_Ptr is
-- other than null, then Reset must be called before the first use -- other than null, then Reset must be called before the first use of
-- of the hash table. -- the hash table.
procedure Set (T : in out Instance; E : Elmt_Ptr); procedure Set (T : in out Instance; E : Elmt_Ptr);
-- Insert the element pointer in the HTable -- Insert the element pointer in the HTable
...@@ -177,7 +177,9 @@ package GNAT.Dynamic_HTables is ...@@ -177,7 +177,9 @@ package GNAT.Dynamic_HTables is
-- associated element. -- associated element.
procedure Reset (T : in out Instance); procedure Reset (T : in out Instance);
-- Removes and frees all elements in the table -- Releases all memory associated with the table. The table can be
-- reused after this call (it is automatically allocated on the first
-- access to the table).
function Get (T : Instance; K : Key) return Element; function Get (T : Instance; K : Key) return Element;
-- Returns the Element associated with a key or No_Element if the -- Returns the Element associated with a key or No_Element if the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment