diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dyn_interning.adb | 35 | ||||
-rw-r--r-- | src/dyn_interning.ads | 10 |
2 files changed, 31 insertions, 14 deletions
diff --git a/src/dyn_interning.adb b/src/dyn_interning.adb index adda22437..96f4edc04 100644 --- a/src/dyn_interning.adb +++ b/src/dyn_interning.adb @@ -68,12 +68,11 @@ package body Dyn_Interning is Deallocate (Old_Hash_Table); end Expand; - procedure Get - (Inst : in out Instance; Params : Params_Type; Res : out Object_Type) + procedure Get_Index + (Inst : in out Instance; Params : Params_Type; Idx : out Index_Type) is Hash_Value : Hash_Value_Type; Hash_Index : Hash_Value_Type; - Idx : Index_Type; begin -- Check if the package was initialized. pragma Assert (Inst.Hash_Table /= null); @@ -87,7 +86,6 @@ package body Dyn_Interning is E : Element_Wrapper renames Inst.Els.Table (Idx); begin if E.Hash = Hash_Value and then Equal (E.Obj, Params) then - Res := E.Obj; return; end if; Idx := E.Next; @@ -102,14 +100,29 @@ package body Dyn_Interning is Hash_Index := Hash_Value and (Inst.Size - 1); end if; - Res := Build (Params); + declare + Res : Object_Type; + begin + Res := Build (Params); + + -- Insert. + Wrapper_Tables.Append (Inst.Els, + (Hash => Hash_Value, + Next => Inst.Hash_Table (Hash_Index), + Obj => Res)); + Inst.Hash_Table (Hash_Index) := Wrapper_Tables.Last (Inst.Els); + end; + + Idx := Wrapper_Tables.Last (Inst.Els); + end Get_Index; - -- Insert. - Wrapper_Tables.Append (Inst.Els, - (Hash => Hash_Value, - Next => Inst.Hash_Table (Hash_Index), - Obj => Res)); - Inst.Hash_Table (Hash_Index) := Wrapper_Tables.Last (Inst.Els); + procedure Get + (Inst : in out Instance; Params : Params_Type; Res : out Object_Type) + is + Idx : Index_Type; + begin + Get_Index (Inst, Params, Idx); + Res := Get_By_Index (Inst, Idx); end Get; function Last_Index (Inst : Instance) return Index_Type is diff --git a/src/dyn_interning.ads b/src/dyn_interning.ads index 2b5dc5ee4..c1bdab420 100644 --- a/src/dyn_interning.ads +++ b/src/dyn_interning.ads @@ -47,14 +47,18 @@ package Dyn_Interning is procedure Free (Inst : in out Instance); + type Index_Type is new Uns32; + No_Index : constant Index_Type := 0; + First_Index : constant Index_Type := 1; + -- If there is already an existing object for PARAMS, return it. -- Otherwise create it. procedure Get (Inst : in out Instance; Params : Params_Type; Res : out Object_Type); - type Index_Type is new Uns32; - No_Index : constant Index_Type := 0; - First_Index : constant Index_Type := 1; + -- Likewise, but return its index. + procedure Get_Index + (Inst : in out Instance; Params : Params_Type; Idx : out Index_Type); -- Get the number of elements in the table. function Last_Index (Inst : Instance) return Index_Type; |