reference counting experiment in h3

This commit is contained in:
2021-08-24 07:17:32 +00:00
parent e07312b402
commit 3cfbd32055
3 changed files with 149 additions and 65 deletions

View File

@ -16,37 +16,46 @@ package H3.Strings is
function To_Character_Array (Str: in Elastic_String) return Character_Array;
function Get_Capacity (Str: in Elastic_String) return System_Size;
pragma Inline (Get_Capacity);
pragma inline (Get_Capacity);
function Get_Length (Str: in Elastic_String) return System_Size;
pragma Inline (Get_Length);
pragma inline (Get_Length);
-- the return type is System_Size for consistency with Get_FIrst_Index.
function Get_First_Index (Str: in Elastic_String) return System_Size;
pragma inline (Get_First_Index);
-- the return type is System_Size because the Last index can be -1 off the System_Index'First.
function Get_Last_Index (Str: in Elastic_String) return System_Size;
pragma inline (Get_Last_index);
function Get_Item (Str: in Elastic_String; Pos: in System_Index) return Character_Type;
pragma Inline (Get_Item);
pragma inline (Get_Item);
-- unsafe
function Get_Slot_Pointer (Str: in Elastic_String) return Thin_Character_Array_Pointer;
pragma Inline (Get_Slot_Pointer);
pragma inline (Get_Slot_Pointer);
function Is_Shared(Str: in Elastic_String) return Standard.Boolean;
pragma inline (Is_Shared);
procedure Clear (Str: in out Elastic_String);
procedure Purge (Str: in out Elastic_String);
procedure Clear (Str: in out Elastic_String);
procedure Append (Str: in out Elastic_String; V: in Character_Array);
procedure Append (Str: in out Elastic_String; V: in Character_Type);
private
type Buffer_Record(Size: System_Size) is limited record
Refs: System_Size := 0;
Slot: Character_Array(1 .. Size);
type Buffer_Record(Capa: System_Size) is limited record
Refs: System_Size := 1;
Slot: Character_Array(1 .. Capa);
Last: System_Size := 0;
end record;
type Buffer_Pointer is access all Buffer_Record;
--Empty_Buffer: aliased Buffer_Record(1);
Empty_Buffer: aliased Buffer_Record := (Size => 1, Refs => 0, Slot => (1 => Null_Character), Last => 0);
Empty_Buffer: aliased Buffer_Record := (Capa => 1, Refs => 0, Slot => (1 => Null_Character), Last => 0);
type Elastic_String is new Ada.Finalization.Controlled with record
Buffer: Buffer_Pointer := Empty_Buffer'Access;
@ -56,6 +65,4 @@ private
overriding procedure Adjust (Str: in out Elastic_String);
overriding procedure Finalize (Str: in out Elastic_String);
end H3.Strings;