From 5c3c78ccf6e87901a9af2369ddc1313692019b7b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 6 Oct 2021 08:05:21 +0000 Subject: [PATCH] renamed Str to Obj --- lib2/h3-arrays.adb | 246 +++++++++++++++++++++----------------------- lib2/h3-arrays.ads | 52 +++++----- lib2/h3-mm.adb | 14 +-- lib2/h3-mm.ads | 6 +- lib2/h3-strings.adb | 4 +- lib2/h3-strings.ads | 2 +- 6 files changed, 157 insertions(+), 167 deletions(-) diff --git a/lib2/h3-arrays.adb b/lib2/h3-arrays.adb index 04a600b..4e2f4c3 100644 --- a/lib2/h3-arrays.adb +++ b/lib2/h3-arrays.adb @@ -3,48 +3,48 @@ with Ada.Unchecked_Deallocation; package body H3.Arrays is BUFFER_ALIGN: constant := 128; -- TODO: change it to a reasonably large value. - function To_Item_Array (Str: in Elastic_Array) return Item_Array is + function To_Item_Array (Obj: in Elastic_Array) return Item_Array is begin - return Str.Buffer.Slot(Str.Buffer.Slot'First .. Str.Buffer.Last); + return Obj.Buffer.Slot(Obj.Buffer.Slot'First .. Obj.Buffer.Last); end To_Item_Array; -- return the buffer capacity excluding the terminator - function Get_Capacity (Str: in Elastic_Array) return System_Size is + function Get_Capacity (Obj: in Elastic_Array) return System_Size is begin - return Str.Buffer.Slot'Length - Terminator_Length; + return Obj.Buffer.Slot'Length - Terminator_Length; end Get_Capacity; -- private. return the buffer capacity including the terminator - function Get_Hard_Capacity (Str: in Elastic_Array) return System_Size is + function Get_Hard_Capacity (Obj: in Elastic_Array) return System_Size is begin - return Str.Buffer.Slot'Length; + return Obj.Buffer.Slot'Length; end Get_Hard_Capacity; pragma Inline (Get_Hard_Capacity); - function Get_Length (Str: in Elastic_Array) return System_Size is + function Get_Length (Obj: in Elastic_Array) return System_Size is begin - return 1 + Str.Buffer.Last - Str.Buffer.Slot'First; + return 1 + Obj.Buffer.Last - Obj.Buffer.Slot'First; end Get_Length; - function Get_First_Index (Str: in Elastic_Array) return System_Size is + function Get_First_Index (Obj: in Elastic_Array) return System_Size is begin - return Str.Buffer.Slot'First; + return Obj.Buffer.Slot'First; end Get_First_Index; - function Get_Last_Index (Str: in Elastic_Array) return System_Size is + function Get_Last_Index (Obj: in Elastic_Array) return System_Size is begin - return Str.Buffer.Last; + return Obj.Buffer.Last; end Get_Last_Index; - function Get_Item (Str: in Elastic_Array; Pos: in System_Index) return Item_Type is + function Get_Item (Obj: in Elastic_Array; Pos: in System_Index) return Item_Type is begin - return Str.Buffer.Slot(Pos); + return Obj.Buffer.Slot(Pos); end Get_Item; -- unsafe as it exposes the internal buffer which can go away. -- assume the system address is equal to the thin pointer in size. - function Get_Slot_Pointer (Str: in Elastic_Array) return Thin_Item_Array_Pointer is - A: System.Address := Str.Buffer.Slot(Str.Buffer.Slot'First)'Address; + function Get_Slot_Pointer (Obj: in Elastic_Array) return Thin_Item_Array_Pointer is + A: System.Address := Obj.Buffer.Slot(Obj.Buffer.Slot'First)'Address; P: Thin_Item_Array_Pointer; for P'Address use A'Address; pragma Import (Ada, P); @@ -52,22 +52,11 @@ package body H3.Arrays is return P; end Get_Slot_Pointer; - function Is_Shared(Str: in Elastic_Array) return Standard.Boolean is + function Is_Shared(Obj: in Elastic_Array) return Standard.Boolean is begin - return Str.Buffer /= Empty_Buffer'Access and then Str.Buffer.Refs > 1; + return Obj.Buffer /= Empty_Buffer'Access and then Obj.Buffer.Refs > 1; end Is_Shared; - procedure Free_Buffer (Str: in out Elastic_Array) is - begin - if Str.Buffer /= Empty_Buffer'Access then - declare - procedure Free is new Ada.Unchecked_Deallocation(Buffer_Record, Buffer_Pointer); - begin - Free (Str.Buffer); - end; - end if; - end Free_Buffer; - procedure Ref_Buffer (Buf: in out Buffer_Pointer) is begin if Buf /= Empty_Buffer'Access then @@ -100,57 +89,57 @@ package body H3.Arrays is end New_Buffer_Container; -- prepare the buffer for writing - procedure Prepare_Buffer (Str: in out Elastic_Array) is + procedure Prepare_Buffer (Obj: in out Elastic_Array) is Tmp: Elastic_Array; begin - if Str.Buffer /= Empty_Buffer'Access then - if Is_Shared(Str) then + if Obj.Buffer /= Empty_Buffer'Access then + if Is_Shared(Obj) then -- The code like this doesn't work correctly in terms of finalization. -- The buffer pointer held inside a finalization controlled record must be -- manipluated through the record itself. otherwise, the Adjust and Finalize -- calls goes incompatible with the reference counting implementation. -- It is because finalization is set on the record rather than the buffer pointer. --Tmp: Buffer_Pointer; - --Tmp := new Buffer_Record(Get_Hard_Capacity(Str)); - --Tmp.Slot := Str.Buffer.Slot; - --Tmp.Last := Str.Buffer.Last; + --Tmp := new Buffer_Record(Get_Hard_Capacity(Obj)); + --Tmp.Slot := Obj.Buffer.Slot; + --Tmp.Last := Obj.Buffer.Last; --Tmp.Refs := 1; - --Unref_Buffer (Str.Buffer); - --Str.Buffer := Tmp; - Tmp := Str; - Str := New_Buffer_Container(Get_Hard_Capacity(Str)); - Str.Buffer.Slot := Tmp.Buffer.Slot; - Str.Buffer.Last := Tmp.Buffer.Last; + --Unref_Buffer (Obj.Buffer); + --Obj.Buffer := Tmp; + Tmp := Obj; + Obj := New_Buffer_Container(Get_Hard_Capacity(Obj)); + Obj.Buffer.Slot := Tmp.Buffer.Slot; + Obj.Buffer.Last := Tmp.Buffer.Last; end if; end if; end Prepare_Buffer; -- prepare the buffer for writing - procedure Prepare_Buffer (Str: in out Elastic_Array; Req_Hard_Capa: in System_Size; Shift_Pos: in System_Size := 0; Shift_Size: in System_Size := 0; Shift_Dir: in Direction := DIRECTION_FORWARD) is + procedure Prepare_Buffer (Obj: in out Elastic_Array; Req_Hard_Capa: in System_Size; Shift_Pos: in System_Size := 0; Shift_Size: in System_Size := 0; Shift_Dir: in Direction := DIRECTION_FORWARD) is Tmp: Elastic_Array; First, Last: System_Size; Hard_Capa: System_Size; begin - First := Get_First_Index(Str); - Last := Get_Last_Index(Str); + First := Get_First_Index(Obj); + Last := Get_Last_Index(Obj); - if Str.Buffer /= Empty_Buffer'Access and then Is_Shared(Str) then - if Req_Hard_Capa < Get_Hard_Capacity(Str) then - Hard_Capa := Get_Hard_Capacity(Str); + if Obj.Buffer /= Empty_Buffer'Access and then Is_Shared(Obj) then + if Req_Hard_Capa < Get_Hard_Capacity(Obj) then + Hard_Capa := Get_Hard_Capacity(Obj); else Hard_Capa := Req_Hard_Capa; end if; - Tmp := Str; - Str := New_Buffer_Container(Hard_Capa); + Tmp := Obj; + Obj := New_Buffer_Container(Hard_Capa); goto COPY_OVER; else - if Req_Hard_Capa > Get_Hard_Capacity(Str) then - Tmp := Str; - Str := New_Buffer_Container(Req_Hard_Capa); + if Req_Hard_Capa > Get_Hard_Capacity(Obj) then + Tmp := Obj; + Obj := New_Buffer_Container(Req_Hard_Capa); goto COPY_OVER; elsif Shift_Pos > 0 then - Tmp := Str; + Tmp := Obj; goto COPY_OVER_WITH_SHIFT; else -- no shift, no change in the buffer @@ -163,8 +152,8 @@ package body H3.Arrays is <> if Shift_Pos <= 0 then -- no shift is required. copy the entire Array including th - Str.Buffer.Slot(First .. Last + Terminator_Length) := Tmp.Buffer.Slot(First .. Last + Terminator_Length); - Str.Buffer.Last := Last; + Obj.Buffer.Slot(First .. Last + Terminator_Length) := Tmp.Buffer.Slot(First .. Last + Terminator_Length); + Obj.Buffer.Last := Last; return; end if; <> @@ -175,152 +164,155 @@ package body H3.Arrays is declare Mid: System_Size := Shift_Pos - Shift_Size; begin - Str.Buffer.Slot(First .. Mid) := Tmp.Buffer.Slot(First .. Mid); - Str.Buffer.Slot(Mid + 1 .. Last - Shift_Size + Terminator_Length) := Tmp.Buffer.Slot(Shift_Pos + 1 .. Last + Terminator_Length); - Str.Buffer.Last := Last - Shift_Size; + Obj.Buffer.Slot(First .. Mid) := Tmp.Buffer.Slot(First .. Mid); + Obj.Buffer.Slot(Mid + 1 .. Last - Shift_Size + Terminator_Length) := Tmp.Buffer.Slot(Shift_Pos + 1 .. Last + Terminator_Length); + Obj.Buffer.Last := Last - Shift_Size; end; else - Str.Buffer.Slot(First .. Shift_Pos - 1) := Tmp.Buffer.Slot(First .. Shift_Pos - 1); - Str.Buffer.Slot(Shift_Pos + Shift_Size .. Last + Shift_Size + Terminator_Length) := Tmp.Buffer.Slot(Shift_Pos .. Last + Terminator_Length); - Str.Buffer.Last := Last + Shift_Size; + Obj.Buffer.Slot(First .. Shift_Pos - 1) := Tmp.Buffer.Slot(First .. Shift_Pos - 1); + Obj.Buffer.Slot(Shift_Pos + Shift_Size .. Last + Shift_Size + Terminator_Length) := Tmp.Buffer.Slot(Shift_Pos .. Last + Terminator_Length); + Obj.Buffer.Last := Last + Shift_Size; end if; end Prepare_Buffer; - procedure Clear (Str: in out Elastic_Array) is + procedure Clear (Obj: in out Elastic_Array) is begin - Prepare_Buffer (Elastic_Array(Str)); - Str.Buffer.Last := Get_First_Index(Str) - 1; - Str.Buffer.Slot(Get_First_Index(Str) .. Get_First_Index(Str) + Terminator_Length - 1) := (others => Terminator_Value); + Prepare_Buffer (Elastic_Array(Obj)); + Obj.Buffer.Last := Get_First_Index(Obj) - 1; + Obj.Buffer.Slot(Get_First_Index(Obj) .. Get_First_Index(Obj) + Terminator_Length - 1) := (others => Terminator_Value); end Clear; - procedure Purge (Str: in out Elastic_Array) is + procedure Purge (Obj: in out Elastic_Array) is begin - Unref_Buffer (Str.Buffer); - Str.Buffer := Empty_Buffer'Access; + Unref_Buffer (Obj.Buffer); + Obj.Buffer := Empty_Buffer'Access; end Purge; - function Calc_Inc_Capa (Str: in Elastic_Array; Inc: in System_Size) return System_Size is + function Calc_Inc_Capa (Obj: in Elastic_Array; Inc: in System_Size) return System_Size is begin - return H3.Align(Get_Length(Str) + Inc + Terminator_Length, BUFFER_ALIGN); + return H3.Align(Get_Length(Obj) + Inc + Terminator_Length, BUFFER_ALIGN); end Calc_Inc_Capa; - procedure Insert (Str: in out Elastic_Array; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1) is + procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1) is Act_Pos: System_Index := Pos; Act_Inc: System_Size := Repeat; begin - if Act_Pos > Str.Buffer.Last then - Act_Pos := Str.Buffer.Last + 1; + if Act_Pos > Obj.Buffer.Last then + Act_Pos := Obj.Buffer.Last + 1; end if; - Prepare_Buffer (Elastic_Array(Str), Calc_Inc_Capa(Str, Act_Inc), Act_Pos, Act_Inc); - Str.Buffer.Slot(Act_Pos .. Act_Pos + Act_Inc - 1) := (others => V); + Prepare_Buffer (Elastic_Array(Obj), Calc_Inc_Capa(Obj, Act_Inc), Act_Pos, Act_Inc); + Obj.Buffer.Slot(Act_Pos .. Act_Pos + Act_Inc - 1) := (others => V); end Insert; - procedure Insert (Str: in out Elastic_Array; Pos: in System_Index; V: in Item_Array) is + procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Array) is Act_Pos: System_Index := Pos; begin - if Act_Pos > Str.Buffer.Last then - Act_Pos := Str.Buffer.Last + 1; + if Act_Pos > Obj.Buffer.Last then + Act_Pos := Obj.Buffer.Last + 1; end if; - Prepare_Buffer (Elastic_Array(Str), Calc_Inc_Capa(Str, V'Length), Act_Pos, V'Length); - Str.Buffer.Slot(Act_Pos .. Act_Pos + V'Length - 1) := V; + Prepare_Buffer (Elastic_Array(Obj), Calc_Inc_Capa(Obj, V'Length), Act_Pos, V'Length); + Obj.Buffer.Slot(Act_Pos .. Act_Pos + V'Length - 1) := V; end Insert; -- TODO: operator "&" that returns a new Elastic_Array - procedure Append (Str: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1) is + procedure Append (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1) is begin - Insert (Str, Get_Last_Index(Str) + 1, V, Repeat); + Insert (Obj, Get_Last_Index(Obj) + 1, V, Repeat); end Append; - procedure Append (Str: in out Elastic_Array; V: in Item_Array) is + procedure Append (Obj: in out Elastic_Array; V: in Item_Array) is begin - Insert (Str, Get_Last_Index(Str) + 1, V); + Insert (Obj, Get_Last_Index(Obj) + 1, V); end Append; - procedure Prepend (Str: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1) is + procedure Prepend (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1) is begin - Insert (Str, Get_First_Index(Str), V, Repeat); + Insert (Obj, Get_First_Index(Obj), V, Repeat); end Prepend; - procedure Prepend (Str: in out Elastic_Array; V: in Item_Array) is + procedure Prepend (Obj: in out Elastic_Array; V: in Item_Array) is begin - Insert (Str, Get_First_Index(Str), V); + Insert (Obj, Get_First_Index(Obj), V); end Prepend; - procedure Replace (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1) is + procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1) is Act_To_Pos, Repl_Len: System_Size; begin - if From_Pos <= To_Pos and then From_Pos <= Str.Buffer.Last then + if From_Pos <= To_Pos and then From_Pos <= Obj.Buffer.Last then Act_To_Pos := To_Pos; - if Act_To_Pos > Str.Buffer.Last then - Act_To_Pos := Str.Buffer.Last; + if Act_To_Pos > Obj.Buffer.Last then + Act_To_Pos := Obj.Buffer.Last; end if; Repl_Len := Act_To_Pos - From_Pos + 1; if Repeat < Repl_Len then - Prepare_Buffer (Elastic_Array(Str), Get_Hard_Capacity(Str), Act_To_Pos, Repl_Len - Repeat, DIRECTION_BACKWARD); + Prepare_Buffer (Elastic_Array(Obj), Get_Hard_Capacity(Obj), Act_To_Pos, Repl_Len - Repeat, DIRECTION_BACKWARD); Act_To_Pos := From_Pos + Repeat - 1; elsif Repeat > Repl_Len then - Prepare_Buffer (Elastic_Array(Str), Calc_Inc_Capa(Str, Repeat - Repl_Len), From_Pos, Repeat - Repl_Len, DIRECTION_FORWARD); + Prepare_Buffer (Elastic_Array(Obj), Calc_Inc_Capa(Obj, Repeat - Repl_Len), From_Pos, Repeat - Repl_Len, DIRECTION_FORWARD); Act_To_Pos := From_Pos + Repeat - 1; else - Prepare_Buffer (Elastic_Array(Str)); + Prepare_Buffer (Elastic_Array(Obj)); end if; - Str.Buffer.Slot(From_Pos .. Act_To_Pos) := (others => V); + Obj.Buffer.Slot(From_Pos .. Act_To_Pos) := (others => V); end if; end Replace; - procedure Replace (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array) is + procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array) is Act_To_Pos, Repl_Len: System_Size; begin - if From_Pos <= To_Pos and then From_Pos <= Str.Buffer.Last then + if From_Pos <= To_Pos and then From_Pos <= Obj.Buffer.Last then Act_To_Pos := To_Pos; - if Act_To_Pos > Str.Buffer.Last then - Act_To_Pos := Str.Buffer.Last; + if Act_To_Pos > Obj.Buffer.Last then + Act_To_Pos := Obj.Buffer.Last; end if; Repl_Len := Act_To_Pos - From_Pos + 1; if V'Length < Repl_Len then - Prepare_Buffer (Elastic_Array(Str), Get_Hard_Capacity(Str), Act_To_Pos, Repl_Len - V'Length, DIRECTION_BACKWARD); + Prepare_Buffer (Elastic_Array(Obj), Get_Hard_Capacity(Obj), Act_To_Pos, Repl_Len - V'Length, DIRECTION_BACKWARD); Act_To_Pos := From_Pos + V'Length - 1; elsif V'Length > Repl_Len then - Prepare_Buffer (Elastic_Array(Str), Calc_Inc_Capa(Str, V'Length - Repl_Len), From_Pos, V'Length - Repl_Len, DIRECTION_FORWARD); + Prepare_Buffer (Elastic_Array(Obj), Calc_Inc_Capa(Obj, V'Length - Repl_Len), From_Pos, V'Length - Repl_Len, DIRECTION_FORWARD); Act_To_Pos := From_Pos + V'Length - 1; else - Prepare_Buffer (Elastic_Array(Str)); + Prepare_Buffer (Elastic_Array(Obj)); end if; - Str.Buffer.Slot(From_Pos .. Act_To_Pos) := V; + Obj.Buffer.Slot(From_Pos .. Act_To_Pos) := V; end if; end Replace; - procedure Delete (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size) is + procedure Delete (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size) is Act_To_Pos: System_Size; begin - if From_Pos <= To_Pos and then From_Pos <= Str.Buffer.Last then + if From_Pos <= To_Pos and then From_Pos <= Obj.Buffer.Last then Act_To_Pos := To_Pos; - if Act_To_Pos > Str.Buffer.Last then - Act_To_Pos := Str.Buffer.Last; + if Act_To_Pos > Obj.Buffer.Last then + Act_To_Pos := Obj.Buffer.Last; end if; - Prepare_Buffer (Elastic_Array(Str), Get_Hard_Capacity(Str), Act_To_Pos, Act_To_Pos - From_Pos + 1, DIRECTION_BACKWARD); + Prepare_Buffer (Elastic_Array(Obj), Get_Hard_Capacity(Obj), Act_To_Pos, Act_To_Pos - From_Pos + 1, DIRECTION_BACKWARD); end if; end Delete; - function Find (Str: in Elastic_Array; V: In Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size is + function Find (Obj: in Elastic_Array; V: In Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size is Act_Start_Pos: System_Index := Start_Pos; begin - if Find_Dir = DIRECTION_FORWARD then - for i in Act_Start_Pos .. Get_Last_Index(Str) loop - if Get_Item(Str, i) = V then + if Find_Dir = DIRECTION_FORWARD then + if Act_Start_Pos < Get_First_Index(Obj) then + Act_Start_Pos := Get_First_Index(Obj); + end if; + for i in Act_Start_Pos .. Get_Last_Index(Obj) loop + if Get_Item(Obj, i) = V then return i; end if; end loop; else - if Act_Start_Pos > Get_Last_Index(Str) then - Act_Start_Pos := Get_Last_Index(Str); + if Act_Start_Pos > Get_Last_Index(Obj) then + Act_Start_Pos := Get_Last_Index(Obj); end if; - for i in reverse Get_First_Index(Str) .. Act_Start_Pos loop - if Get_Item(Str, i) = V then + for i in reverse Get_First_Index(Obj) .. Act_Start_Pos loop + if Get_Item(Obj, i) = V then return i; end if; end loop; @@ -328,37 +320,37 @@ package body H3.Arrays is return System_Size'First; end Find; - --function Find (Str: in Elastic_Array; V: In Item_Array; From_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); + --function Find (Obj: in Elastic_Array; V: In Item_Array; From_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); - function "=" (Str: in Elastic_Array; Str2: in Elastic_Array) return Standard.Boolean is + function "=" (Obj: in Elastic_Array; Obj2: in Elastic_Array) return Standard.Boolean is begin - return Str.Buffer = Str2.Buffer or else Str.Buffer.Slot(Get_First_Index(Str) .. Get_Last_Index(Str)) = Str2.Buffer.Slot(Get_First_Index(Str2) .. Get_Last_Index(Str2)); + return Obj.Buffer = Obj2.Buffer or else Obj.Buffer.Slot(Get_First_Index(Obj) .. Get_Last_Index(Obj)) = Obj2.Buffer.Slot(Get_First_Index(Obj2) .. Get_Last_Index(Obj2)); end "="; - function "=" (Str: in Elastic_Array; Str2: in Item_Array) return Standard.Boolean is + function "=" (Obj: in Elastic_Array; Obj2: in Item_Array) return Standard.Boolean is begin - return Str.Buffer.Slot(Get_First_Index(Str) .. Get_Last_Index(Str)) = Str2; + return Obj.Buffer.Slot(Get_First_Index(Obj) .. Get_Last_Index(Obj)) = Obj2; end "="; -- --------------------------------------------------------------------- -- Controlled Management -- --------------------------------------------------------------------- - procedure Initialize (Str: in out Elastic_Array) is + procedure Initialize (Obj: in out Elastic_Array) is begin -- the Array is initialized to the empty buffer all the time. -- there is no need to reference the buffer. null; end Initialize; - procedure Adjust (Str: in out Elastic_Array) is + procedure Adjust (Obj: in out Elastic_Array) is begin - Ref_Buffer (Str.Buffer); + Ref_Buffer (Obj.Buffer); end Adjust; - procedure Finalize (Str: in out Elastic_Array) is + procedure Finalize (Obj: in out Elastic_Array) is begin - Unref_Buffer (Str.Buffer); + Unref_Buffer (Obj.Buffer); end Finalize; end H3.Arrays; diff --git a/lib2/h3-arrays.ads b/lib2/h3-arrays.ads index b3a4e8a..f65aa6e 100644 --- a/lib2/h3-arrays.ads +++ b/lib2/h3-arrays.ads @@ -19,55 +19,55 @@ package H3.Arrays is subtype Thin_Item_Array is Item_Array(System_Index'Range); type Thin_Item_Array_Pointer is access Thin_Item_Array; - function To_Item_Array (Str: in Elastic_Array) return Item_Array; + function To_Item_Array (Obj: in Elastic_Array) return Item_Array; - function Get_Capacity (Str: in Elastic_Array) return System_Size; + function Get_Capacity (Obj: in Elastic_Array) return System_Size; pragma Inline (Get_Capacity); - function Get_Length (Str: in Elastic_Array) return System_Size; + function Get_Length (Obj: in Elastic_Array) return System_Size; pragma Inline (Get_Length); -- the return type is System_Size for consistency with Get_Last_Index. - function Get_First_Index (Str: in Elastic_Array) return System_Size; + function Get_First_Index (Obj: in Elastic_Array) return System_Size; pragma Inline (Get_First_Index); -- the return type is System_Size because the Last index is -1 off the System_Index'First for an empty array - function Get_Last_Index (Str: in Elastic_Array) return System_Size; + function Get_Last_Index (Obj: in Elastic_Array) return System_Size; pragma Inline (Get_Last_index); - function Get_Item (Str: in Elastic_Array; Pos: in System_Index) return Item_Type; + function Get_Item (Obj: in Elastic_Array; Pos: in System_Index) return Item_Type; pragma Inline (Get_Item); -- unsafe - function Get_Slot_Pointer (Str: in Elastic_Array) return Thin_Item_Array_Pointer; + function Get_Slot_Pointer (Obj: in Elastic_Array) return Thin_Item_Array_Pointer; pragma Inline (Get_Slot_Pointer); - function Is_Shared(Str: in Elastic_Array) return Standard.Boolean; + function Is_Shared(Obj: in Elastic_Array) return Standard.Boolean; pragma Inline (Is_Shared); - procedure Clear (Str: in out Elastic_Array); - procedure Purge (Str: in out Elastic_Array); -- clear and reset the buffer to Empty_Buffer. + procedure Clear (Obj: in out Elastic_Array); + procedure Purge (Obj: in out Elastic_Array); -- clear and reset the buffer to Empty_Buffer. - procedure Insert (Str: in out Elastic_Array; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1); - procedure Insert (Str: in out Elastic_Array; Pos: in System_Index; V: in Item_Array); + procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1); + procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Array); - procedure Append (Str: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1); - procedure Append (Str: in out Elastic_Array; V: in Item_Array); + procedure Append (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1); + procedure Append (Obj: in out Elastic_Array; V: in Item_Array); - procedure Prepend (Str: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1); - procedure Prepend (Str: in out Elastic_Array; V: in Item_Array); + procedure Prepend (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1); + procedure Prepend (Obj: in out Elastic_Array; V: in Item_Array); - procedure Replace (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1); - procedure Replace (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array); + procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1); + procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array); - procedure Delete (Str: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size); + procedure Delete (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size); - function Find (Str: in Elastic_Array; V: In Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size; - --function Find (Str: in Elastic_Array; V: In Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); + function Find (Obj: in Elastic_Array; V: In Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size; + --function Find (Obj: in Elastic_Array; V: In Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD); - function "=" (Str: in Elastic_Array; Str2: in Elastic_Array) return Standard.Boolean; - function "=" (Str: in Elastic_Array; Str2: in Item_Array) return Standard.Boolean; + function "=" (Obj: in Elastic_Array; Obj2: in Elastic_Array) return Standard.Boolean; + function "=" (Obj: in Elastic_Array; Obj2: in Item_Array) return Standard.Boolean; private type Buffer_Record(Capa: System_Size) is limited record @@ -86,8 +86,8 @@ private Buffer: Buffer_Pointer := Empty_Buffer'Access; end record; - overriding procedure Initialize (Str: in out Elastic_Array); - overriding procedure Adjust (Str: in out Elastic_Array); - overriding procedure Finalize (Str: in out Elastic_Array); + overriding procedure Initialize (Obj: in out Elastic_Array); + overriding procedure Adjust (Obj: in out Elastic_Array); + overriding procedure Finalize (Obj: in out Elastic_Array); end H3.Arrays; diff --git a/lib2/h3-mm.adb b/lib2/h3-mm.adb index fd83446..4d17d8a 100644 --- a/lib2/h3-mm.adb +++ b/lib2/h3-mm.adb @@ -5,7 +5,7 @@ package body H3.MM is begin Finalize (R); R.Data := new Ref_Counted_Record; - R.Data.Ref_Count := 1; + R.Data.Refs := 1; --System.Atomic_Counters.Initialize (R.Data.Ref_Count); -- initialize to 1 end Create; @@ -26,8 +26,8 @@ package body H3.MM is function Is_Shared (R: in Ref_Counted) return Standard.Boolean is begin - --return R.Data /= null and then not System.Atomic_Counters.Is_One(R.Data.Ref_Count); - return R.Data /= null and then R.Data.Ref_Count > 1; + --return R.Data /= null and then not System.Atomic_Counters.Is_One(R.Data.Refs); + return R.Data /= null and then R.Data.Refs > 1; end Is_Shared; procedure Initialize (R: in out Ref_Counted) is @@ -38,8 +38,8 @@ package body H3.MM is procedure Adjust (R: in out Ref_Counted) is begin if R.Data /= null then - R.Data.Ref_Count := R.Data.Ref_Count + 1; - --System.Atomic_Counters.Increment (R.Data.Ref_Count); + R.Data.Refs := R.Data.Refs + 1; + --System.Atomic_Counters.Increment (R.Data.Refs); end if; end Adjust; @@ -52,10 +52,10 @@ package body H3.MM is -- Dealloc (R.Data); -- -- R.DAta must be null here --end if; - if R.Data.Ref_Count = 1 then + if R.Data.Refs = 1 then Dealloc (R.Data); else - R.Data.Ref_Count := R.Data.Ref_Count - 1; + R.Data.Refs := R.Data.Refs - 1; end if; end if; end Finalize; diff --git a/lib2/h3-mm.ads b/lib2/h3-mm.ads index 205a395..d46bb37 100644 --- a/lib2/h3-mm.ads +++ b/lib2/h3-mm.ads @@ -7,8 +7,8 @@ package H3.MM is type Item_Pointer is access all Item_Type; type Ref_Counted_Record is record - --Ref_Count: System.Atomic_Counters.Atomic_Counter; - Ref_Count: System_Size; + --Refs: System.Atomic_Counters.Atomic_Counter; + Refs: System_Size; Item: aliased Item_Type; end record; @@ -27,10 +27,8 @@ package H3.MM is function Is_Shared (R: in Ref_Counted) return Standard.Boolean; pragma Inline(Is_Shared); - overriding procedure Initialize (R: in out Ref_Counted); overriding procedure Adjust (R: in out Ref_Counted); overriding procedure Finalize (R: in out Ref_Counted); - end H3.MM; diff --git a/lib2/h3-strings.adb b/lib2/h3-strings.adb index d86eb35..0ba5439 100644 --- a/lib2/h3-strings.adb +++ b/lib2/h3-strings.adb @@ -1,8 +1,8 @@ package body H3.Strings is - procedure Append (Str: in out Elastic_String; V: in Character_Array) is + procedure Append (Obj: in out Elastic_String; V: in Character_Array) is begin - P.Append (P.Elastic_Array(Str), V); + P.Append (P.Elastic_Array(Obj), V); end; end H3.Strings; diff --git a/lib2/h3-strings.ads b/lib2/h3-strings.ads index 329592e..5ed7288 100644 --- a/lib2/h3-strings.ads +++ b/lib2/h3-strings.ads @@ -18,6 +18,6 @@ package H3.Strings is null; end record; - overriding procedure Append (Str: in out Elastic_String; V: in Character_Array); + overriding procedure Append (Obj: in out Elastic_String; V: in Character_Array); end H3.Strings;