]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Avoid linear search when ensuring dependency on System
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 24 May 2021 14:14:40 +0000 (16:14 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 8 Jul 2021 13:34:16 +0000 (13:34 +0000)
gcc/ada/

* lib-writ.adb (Ensure_System_Dependency): Replace search in
Lib.Units with a search in Lib.Unit_Names.

gcc/ada/lib-writ.adb

index 416052c943e5b52d1803fb44f80371f761c273d4..1b2912a53b2ce8654ac3f7e38784cff870baa24e 100644 (file)
@@ -137,7 +137,8 @@ package body Lib.Writ is
    ------------------------------
 
    procedure Ensure_System_Dependency is
-      System_Uname : Unit_Name_Type;
+      System_Uname : constant Unit_Name_Type :=
+        Name_To_Unit_Name (Name_System);
       --  Unit name for system spec if needed for dummy entry
 
       System_Fname : File_Name_Type;
@@ -146,11 +147,9 @@ package body Lib.Writ is
    begin
       --  Nothing to do if we already compiled System
 
-      for Unum in Units.First .. Last_Unit loop
-         if Source_Index (Unum) = System_Source_File_Index then
-            return;
-         end if;
-      end loop;
+      if Unit_Names.Get (System_Uname) /= No_Unit then
+         return;
+      end if;
 
       --  If no entry for system.ads in the units table, then add a entry
       --  to the units table for system.ads, which will be referenced when
@@ -158,7 +157,6 @@ package body Lib.Writ is
       --  on system as a result of Targparm scanning the system.ads file to
       --  determine the target dependent parameters for the compilation.
 
-      System_Uname := Name_To_Unit_Name (Name_System);
       System_Fname := File_Name (System_Source_File_Index);
 
       Units.Increment_Last;