aboutsummaryrefslogtreecommitdiffstats
path: root/src/dyn_tables.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-07-25 05:12:24 +0200
committerTristan Gingold <tgingold@free.fr>2022-07-25 05:12:24 +0200
commit4030d67a73d4b5254912c586b6638ca3851855d6 (patch)
tree4922d6f35cf9160291eba352ee5f0b2254d41342 /src/dyn_tables.adb
parent88a4798285037a18cb7d27057474d52eca819520 (diff)
downloadghdl-4030d67a73d4b5254912c586b6638ca3851855d6.tar.gz
ghdl-4030d67a73d4b5254912c586b6638ca3851855d6.tar.bz2
ghdl-4030d67a73d4b5254912c586b6638ca3851855d6.zip
dyn_tables,tables: add Reserve. For #2139
Diffstat (limited to 'src/dyn_tables.adb')
-rw-r--r--src/dyn_tables.adb22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/dyn_tables.adb b/src/dyn_tables.adb
index 972ffd492..cf292d4fb 100644
--- a/src/dyn_tables.adb
+++ b/src/dyn_tables.adb
@@ -23,8 +23,9 @@ package body Dyn_Tables is
size_t (Table_Type'Component_Size / System.Storage_Unit);
-- Expand the table by doubling its size. The table must have been
- -- initialized.
- procedure Expand (T : in out Instance; Num : Unsigned)
+ -- initialized. Memory space for the extra elements are allocated but the
+ -- length of the table is not increased.
+ procedure Reserve (T : in out Instance; Num : Unsigned)
is
-- For efficiency, directly call realloc.
function Crealloc (Ptr : Table_Thin_Ptr; Size : size_t)
@@ -42,10 +43,9 @@ package body Dyn_Tables is
if New_Last < T.Priv.Last_Pos then
raise Constraint_Error;
end if;
- T.Priv.Last_Pos := New_Last;
-- Check if need to reallocate.
- if T.Priv.Last_Pos < T.Priv.Length then
+ if New_Last < T.Priv.Length then
return;
end if;
@@ -59,7 +59,7 @@ package body Dyn_Tables is
end if;
T.Priv.Length := New_Len;
- exit when New_Len > T.Priv.Last_Pos;
+ exit when New_Len > New_Last;
end loop;
-- Realloc and check result.
@@ -70,8 +70,20 @@ package body Dyn_Tables is
if T.Table = null then
raise Storage_Error;
end if;
+ end Reserve;
+
+ -- Expand the table (allocate and increase the length).
+ procedure Expand (T : in out Instance; Num : Unsigned) is
+ begin
+ Reserve (T, Num);
+ T.Priv.Last_Pos := T.Priv.Last_Pos + Num;
end Expand;
+ procedure Reserve (T : in out Instance; Num : Natural) is
+ begin
+ Reserve (T, Unsigned (Num));
+ end Reserve;
+
procedure Allocate (T : in out Instance; Num : Natural := 1) is
begin
Expand (T, Unsigned (Num));