First_Formal is not as cheap as it used to be so this patch eliminates a few
redundant invocations in Operator_Matches_Spec. No functional changes.
Tested on x86_64-pc-linux-gnu, committed on trunk
2016-04-18 Eric Botcazou <[email protected]>
* sem_type.adb (Operator_Matches_Spec): Call First_Formal on
New_S only once at the beginning of the function.
Index: sem_type.adb
===================================================================
--- sem_type.adb (revision 235093)
+++ sem_type.adb (working copy)
@@ -3026,20 +3026,21 @@
---------------------------
function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
- Op_Name : constant Name_Id := Chars (Op);
- T : constant Entity_Id := Etype (New_S);
- New_F : Entity_Id;
- Old_F : Entity_Id;
- Num : Int;
- T1 : Entity_Id;
- T2 : Entity_Id;
+ Op_Name : constant Name_Id := Chars (Op);
+ T : constant Entity_Id := Etype (New_S);
+ New_First_F : constant Entity_Id := First_Formal (New_S);
+ New_F : Entity_Id;
+ Old_F : Entity_Id;
+ Num : Int;
+ T1 : Entity_Id;
+ T2 : Entity_Id;
begin
-- To verify that a predefined operator matches a given signature,
-- do a case analysis of the operator classes. Function can have one
-- or two formals and must have the proper result type.
- New_F := First_Formal (New_S);
+ New_F := New_First_F;
Old_F := First_Formal (Op);
Num := 0;
while Present (New_F) and then Present (Old_F) loop
@@ -3056,7 +3057,7 @@
-- Unary operators
elsif Num = 1 then
- T1 := Etype (First_Formal (New_S));
+ T1 := Etype (New_First_F);
if Nam_In (Op_Name, Name_Op_Subtract, Name_Op_Add, Name_Op_Abs) then
return Base_Type (T1) = Base_Type (T)
@@ -3073,8 +3074,8 @@
-- Binary operators
else
- T1 := Etype (First_Formal (New_S));
- T2 := Etype (Next_Formal (First_Formal (New_S)));
+ T1 := Etype (New_First_F);
+ T2 := Etype (Next_Formal (New_First_F));
if Nam_In (Op_Name, Name_Op_And, Name_Op_Or, Name_Op_Xor) then
return Base_Type (T1) = Base_Type (T2)