-- This is called when we are about to set the value of Last to a value
-- that is larger than Last_Allocated. This reallocates the table to the
-- larger size, as indicated by New_Last. At the time this is called,
- -- T.P.Last is still the old value.
+ -- Last (T) is still the old value, and this does not modify it.
--------------
-- Allocate --
-- Note that Num can be negative
pragma Assert (not T.Locked);
- Set_Last (T, T.P.Last + Table_Index_Type'Base (Num));
+ Set_Last (T, Last (T) + Table_Index_Type'Base (Num));
end Allocate;
------------
------------
procedure Append (T : in out Instance; New_Val : Table_Component_Type) is
- begin
pragma Assert (not T.Locked);
- Set_Item (T, T.P.Last + 1, New_Val);
+ New_Last : constant Table_Last_Type := Last (T) + 1;
+ begin
+ if New_Last <= T.P.Last_Allocated then
+ -- fast path
+ T.P.Last := New_Last;
+ T.Table (New_Last) := New_Val;
+
+ else
+ Set_Item (T, New_Last, New_Val);
+ end if;
end Append;
----------------
begin
if T.Table /= Empty_Table_Ptr then
- New_Table (First .. T.P.Last) := Old_Table (First .. T.P.Last);
+ New_Table (First .. Last (T)) := Old_Table (First .. Last (T));
Free (Old_Table);
end if;
--------------
function Is_Empty (T : Instance) return Boolean is
- Result : constant Boolean := T.P.Last = Table_Low_Bound - 1;
begin
- pragma Assert (Result = (T.Table = Empty_Table_Ptr));
- return Result;
+ return Last (T) = Table_Low_Bound - 1;
end Is_Empty;
----------
subtype Table_Length_Type is Table_Index_Type'Base
range 0 .. Table_Index_Type'Base'Last;
- Length : constant Table_Length_Type := T.P.Last - First + 1;
+ Length : constant Table_Length_Type := Last (T) - First + 1;
Comp_Size_In_Bytes : constant Table_Length_Type :=
Table_Type'Component_Size / System.Storage_Unit;
begin
if Release_Threshold = 0 or else Length < Length_Threshold then
- return T.P.Last;
+ return Last (T);
else
declare
Extra_Length : constant Table_Length_Type := Length / 1000;
begin
if New_Last_Alloc < T.P.Last_Allocated then
- pragma Assert (T.P.Last < T.P.Last_Allocated);
+ pragma Assert (Last (T) < T.P.Last_Allocated);
pragma Assert (T.Table /= Empty_Table_Ptr);
declare
Index : Valid_Table_Index_Type;
Item : Table_Component_Type)
is
+ begin
pragma Assert (not T.Locked);
- Item_Copy : constant Table_Component_Type := Item;
- begin
-- If Set_Last is going to reallocate the table, we make a copy of Item,
-- in case the call was "Set_Item (T, X, T.Table (Y));", and Item is
-- passed by reference. Without the copy, we would deallocate the array
T.Table (Index) := Item_Copy;
end;
- return;
- end if;
+ else
+ if Index > Last (T) then
+ Set_Last (T, Index);
+ end if;
- if Index > T.P.Last then
- Set_Last (T, Index);
+ T.Table (Index) := Item;
end if;
-
- T.Table (Index) := Item_Copy;
end Set_Item;
--------------
function Is_Empty return Boolean;
procedure Init;
+ pragma Inline (Init);
procedure Free;
+ pragma Inline (Free);
function First return Table_Index_Type;
pragma Inline (First);
pragma Inline (Last);
procedure Release;
+ pragma Inline (Release);
procedure Set_Last (New_Val : Table_Last_Type);
pragma Inline (Set_Last);
pragma Inline (Append);
procedure Append_All (New_Vals : Table_Type);
+ pragma Inline (Append_All);
procedure Set_Item
(Index : Valid_Table_Index_Type;
-- Type used for Save/Restore subprograms
function Save return Saved_Table;
+ pragma Inline (Save);
-- Resets table to empty, but saves old contents of table in returned
-- value, for possible later restoration by a call to Restore.
procedure Restore (T : in out Saved_Table);
+ pragma Inline (Restore);
-- Given a Saved_Table value returned by a prior call to Save, restores
-- the table to the state it was in at the time of the Save call.
Item : Table_Component_Type;
Quit : in out Boolean) is <>;
procedure For_Each;
+ pragma Inline (For_Each);
generic
with function Lt (Comp1, Comp2 : Table_Component_Type) return Boolean;
procedure Sort_Table;
+ pragma Inline (Sort_Table);
end GNAT.Table;