diff mbox

[Ada] Cache value returned by Is_Compilable

Message ID 20101018100355.GA26563@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 18, 2010, 10:03 a.m. UTC
This is a small optimization for GNAT builders.

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-18  Vincent Celier  <celier@adacore.com>

	* prj.adb (Is_Compilable): On first call for a source, cache value in
	component Compilable.
	* prj.ads (Source_Data): New component Compilable, to cache the value
	returned by function Is_Compilable.
diff mbox

Patch

Index: prj.adb
===================================================================
--- prj.adb	(revision 165610)
+++ prj.adb	(working copy)
@@ -1154,12 +1154,29 @@  package body Prj is
 
    function Is_Compilable (Source : Source_Id) return Boolean is
    begin
-      return Source.Language.Config.Compiler_Driver /= No_File
-        and then Length_Of_Name (Source.Language.Config.Compiler_Driver) /= 0
-        and then not Source.Locally_Removed
-        and then (Source.Language.Config.Kind /= File_Based
-                    or else
-                  Source.Kind /= Spec);
+      case Source.Compilable is
+         when Unknown =>
+            if Source.Language.Config.Compiler_Driver /= No_File
+              and then
+                Length_Of_Name (Source.Language.Config.Compiler_Driver) /= 0
+              and then not Source.Locally_Removed
+              and then (Source.Language.Config.Kind /= File_Based
+                        or else
+                          Source.Kind /= Spec)
+            then
+               Source.Compilable := Yes;
+               return True;
+            else
+               Source.Compilable := No;
+               return False;
+            end if;
+
+         when Yes =>
+            return True;
+
+         when No =>
+            return False;
+      end case;
    end Is_Compilable;
 
    ------------------------------
Index: prj.ads
===================================================================
--- prj.ads	(revision 165611)
+++ prj.ads	(working copy)
@@ -706,6 +706,10 @@  package Prj is
       --  file). Index is 0 if there is either no unit or a single one, and
       --  starts at 1 when there are multiple units
 
+      Compilable : Yes_No_Unknown := Unknown;
+      --  Updated at the first call to Is_Compilable. Yes if source file is
+      --  compilable.
+
       Locally_Removed : Boolean := False;
       --  True if the source has been "excluded"
 
@@ -788,6 +792,7 @@  package Prj is
                        Unit                   => No_Unit_Index,
                        Index                  => 0,
                        Locally_Removed        => False,
+                       Compilable             => Unknown,
                        Replaced_By            => No_Source,
                        File                   => No_File,
                        Display_File           => No_File,