[Ada] Avoid potentially repeated calls to Prefix in Eval_Slice
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 29 Sep 2020 10:40:39 +0000 (12:40 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 26 Nov 2020 08:39:52 +0000 (03:39 -0500)
gcc/ada/

* sem_eval.adb (Eval_Slice): Refactor repeated calls to Prefix
with a local constant (named just like in Resolve_Slice).

gcc/ada/sem_eval.adb

index e453bc1..4dc5248 100644 (file)
@@ -3944,6 +3944,7 @@ package body Sem_Eval is
 
    procedure Eval_Slice (N : Node_Id) is
       Drange : constant Node_Id := Discrete_Range (N);
+      Name   : constant Node_Id := Prefix (N);
 
    begin
       if Nkind (Drange) = N_Range then
@@ -3955,9 +3956,9 @@ package body Sem_Eval is
       --  the type of A, is redundant, the slice can be replaced with A, and
       --  this is worth a warning.
 
-      if Is_Entity_Name (Prefix (N)) then
+      if Is_Entity_Name (Name) then
          declare
-            E : constant Entity_Id := Entity (Prefix (N));
+            E : constant Entity_Id := Entity (Name);
             T : constant Entity_Id := Etype (E);
 
          begin