]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Disable Vet calls when container checks are disabled
authorBob Duff <duff@adacore.com>
Thu, 7 Apr 2022 16:58:56 +0000 (12:58 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 18 May 2022 08:41:07 +0000 (08:41 +0000)
Calls to various Vet functions are used throughout the containers
packages to check internal consistency. This patch improves efficiency
by disabling these calls when Container_Checks are suppressed.

gcc/ada/

* libgnat/a-crbtgo.ads, libgnat/a-rbtgbo.ads,
libgnat/a-cbdlli.adb, libgnat/a-cbhama.adb,
libgnat/a-cbhase.adb, libgnat/a-cdlili.adb,
libgnat/a-cfdlli.adb, libgnat/a-cfhama.adb,
libgnat/a-cfhase.adb, libgnat/a-cidlli.adb,
libgnat/a-cihama.adb, libgnat/a-cihase.adb,
libgnat/a-cohama.adb, libgnat/a-cohase.adb,
libgnat/a-crbtgo.adb, libgnat/a-crdlli.adb, libgnat/a-rbtgbo.adb
(Vet): Make the Vet functions do nothing when
Container_Checks'Enabled is False, and inline them, so the calls
disappear when optimizing.

17 files changed:
gcc/ada/libgnat/a-cbdlli.adb
gcc/ada/libgnat/a-cbhama.adb
gcc/ada/libgnat/a-cbhase.adb
gcc/ada/libgnat/a-cdlili.adb
gcc/ada/libgnat/a-cfdlli.adb
gcc/ada/libgnat/a-cfhama.adb
gcc/ada/libgnat/a-cfhase.adb
gcc/ada/libgnat/a-cidlli.adb
gcc/ada/libgnat/a-cihama.adb
gcc/ada/libgnat/a-cihase.adb
gcc/ada/libgnat/a-cohama.adb
gcc/ada/libgnat/a-cohase.adb
gcc/ada/libgnat/a-crbtgo.adb
gcc/ada/libgnat/a-crbtgo.ads
gcc/ada/libgnat/a-crdlli.adb
gcc/ada/libgnat/a-rbtgbo.adb
gcc/ada/libgnat/a-rbtgbo.ads

index 540fc932e71e233bda4ea7124672eaf8c227e514..d8cf6c3c7a44df6bae7fa2f9cc42a883b7ff37da 100644 (file)
@@ -75,7 +75,7 @@ is
       Src_Pos : Count_Type;
       Tgt_Pos : out Count_Type);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
    --  Checks invariants of the cursor and its designated container, as a
    --  simple way of detecting dangling references (see operation Free for a
    --  description of the detection mechanism), returning True if all checks
@@ -2210,6 +2210,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return Position.Container = null;
       end if;
index 59c4c7e2842e24c24c73744c5d72148291a7fa7d..f557ff9c4abb094005418a3cb4f8a972e8499b57 100644 (file)
@@ -66,7 +66,7 @@ is
    procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    --------------------------
    -- Local Instantiations --
@@ -1175,6 +1175,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return Position.Container = null;
       end if;
index 3c1c7b4bf673b003952d4ade6a2af50c6da4c0dc..9076d8e813201c394320cf01d00a0a4a64c60eae 100644 (file)
@@ -79,7 +79,7 @@ is
    procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    --------------------------
    -- Local Instantiations --
@@ -1496,6 +1496,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return Position.Container = null;
       end if;
index 582860742c11537330ae0682099a0532188f732b..22cb14679d29fad5766a26f088252d46428d6181 100644 (file)
@@ -64,7 +64,7 @@ is
       Source   : in out List;
       Position : Node_Access);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
    --  Checks invariants of the cursor and its designated container, as a
    --  simple way of detecting dangling references (see operation Free for a
    --  description of the detection mechanism), returning True if all checks
@@ -1991,6 +1991,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index 14f0304e2080cf61fa8a2ef9339cb9b544e51f9d..383d031d71548216a828ec3e7d009f74bafde2c3 100644 (file)
@@ -48,7 +48,7 @@ is
       Before    : Count_Type;
       New_Node  : Count_Type);
 
-   function Vet (L : List; Position : Cursor) return Boolean;
+   function Vet (L : List; Position : Cursor) return Boolean with Inline;
 
    ---------
    -- "=" --
@@ -1766,8 +1766,11 @@ is
 
    function Vet (L : List; Position : Cursor) return Boolean is
       N : Node_Array renames L.Nodes;
-
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if L.Length = 0 then
          return False;
       end if;
index c2a7c5958541db3b2f6ad06dd0d6ae089b01e045..0b60a0105127650d388c7a3acd2077c986756d2f 100644 (file)
@@ -68,7 +68,8 @@ is
    procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
    pragma Inline (Set_Next);
 
-   function Vet (Container : Map; Position : Cursor) return Boolean;
+   function Vet (Container : Map; Position : Cursor) return Boolean
+     with Inline;
 
    --------------------------
    -- Local Instantiations --
@@ -901,6 +902,10 @@ is
 
    function Vet (Container : Map; Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return True;
       end if;
index 834f43a6c4e16e14cfed4bbc8cbe4a94d6f27d78..544ad2bfa79766cdce8234d2fc25f89febce01e1 100644 (file)
@@ -89,7 +89,8 @@ is
    procedure Set_Next (Node : in out Node_Type; Next : Count_Type);
    pragma Inline (Set_Next);
 
-   function Vet (Container : Set; Position : Cursor) return Boolean;
+   function Vet (Container : Set; Position : Cursor) return Boolean
+     with Inline;
 
    --------------------------
    -- Local Instantiations --
@@ -1506,6 +1507,10 @@ is
 
    function Vet (Container : Set; Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return True;
       end if;
index 9a11f4cc56ca72f4758b9c328ed6b79b622ae4a8..b34df0445ddcf721b1542141671e1f8fa4f600d0 100644 (file)
@@ -67,7 +67,7 @@ is
       Source   : in out List;
       Position : Node_Access);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
    --  Checks invariants of the cursor and its designated container, as a
    --  simple way of detecting dangling references (see operation Free for a
    --  description of the detection mechanism), returning True if all checks
@@ -2103,6 +2103,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index 4734e64069549b469cbf7770cef474fecf989978..30a2f4daf925c2b443f6da3dece122c0b7cbb94c 100644 (file)
@@ -85,7 +85,7 @@ is
    procedure Set_Next (Node : Node_Access; Next : Node_Access);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    procedure Write_Node
      (Stream : not null access Root_Stream_Type'Class;
@@ -1299,6 +1299,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index cb55bbb9ed4950ad214f2f26de412504ac718fec..090d01cb4724c4e202083cad91687985695909a6 100644 (file)
@@ -99,7 +99,7 @@ is
    procedure Set_Next (Node : Node_Access; Next : Node_Access);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    procedure Write_Node
      (Stream : not null access Root_Stream_Type'Class;
@@ -1932,6 +1932,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index 2fcf4c897b4ff2ea73f8270c26c5af7ed9a6761a..013e2cd03d09d387d7ce65ffa94b3bc3506fa7c1 100644 (file)
@@ -80,7 +80,7 @@ is
    procedure Set_Next (Node : Node_Access; Next : Node_Access);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    procedure Write_Node
      (Stream : not null access Root_Stream_Type'Class;
@@ -1156,6 +1156,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index e9662cca13b59ba6b9940f9d95d69621e8c03f6d..986b354ad7266d3e83c206e10f39591200f15bd7 100644 (file)
@@ -99,7 +99,7 @@ is
    procedure Set_Next (Node : Node_Access; Next : Node_Access);
    pragma Inline (Set_Next);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    procedure Write_Node
      (Stream : not null access Root_Stream_Type'Class;
@@ -1749,6 +1749,10 @@ is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = null then
          return Position.Container = null;
       end if;
index 7757aadaf1c8a24d7d9f74135339fb1141c158c2..d689b1cb2adaa0328ed380f008fb71fab7bfd564 100644 (file)
@@ -1060,6 +1060,10 @@ package body Ada.Containers.Red_Black_Trees.Generic_Operations is
 
    function Vet (Tree : Tree_Type; Node : Node_Access) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Node = null then
          return True;
       end if;
index fde9c4572bcad812f2522bea2167fbd424945ea8..609fe4b4814c5411e2c99705efc30af503068bf3 100644 (file)
@@ -61,7 +61,8 @@ package Ada.Containers.Red_Black_Trees.Generic_Operations is
 
    --  procedure Check_Invariant (Tree : Tree_Type);
 
-   function Vet (Tree : Tree_Type; Node : Node_Access) return Boolean;
+   function Vet (Tree : Tree_Type; Node : Node_Access) return Boolean
+     with Inline;
    --  Inspects Node to determine (to the extent possible) whether
    --  the node is valid; used to detect if the node is dangling.
 
index a5fe43124133d591d06c24628be003980e7469b2..bdb6475d67f376366e1b0401c52a50229e011b89 100644 (file)
@@ -51,7 +51,7 @@ package body Ada.Containers.Restricted_Doubly_Linked_Lists is
       Before    : Count_Type;
       New_Node  : Count_Type);
 
-   function Vet (Position : Cursor) return Boolean;
+   function Vet (Position : Cursor) return Boolean with Inline;
 
    ---------
    -- "=" --
@@ -1330,6 +1330,10 @@ package body Ada.Containers.Restricted_Doubly_Linked_Lists is
 
    function Vet (Position : Cursor) return Boolean is
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Position.Node = 0 then
          return Position.Container = null;
       end if;
index c077788c48dca44263c3653362f41b9e9426110e..0c3f25f6d81469bbb72d1272ef0adf86d8e9db54 100644 (file)
@@ -1038,8 +1038,11 @@ package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
    function Vet (Tree : Tree_Type'Class; Index : Count_Type) return Boolean is
       Nodes : Nodes_Type renames Tree.Nodes;
       Node  : Node_Type renames Nodes (Index);
-
    begin
+      if not Container_Checks'Enabled then
+         return True;
+      end if;
+
       if Parent (Node) = Index
         or else Left (Node) = Index
         or else Right (Node) = Index
index 97c0ee021df105bffe1088adc1f03bc95be09ce8..b3e0106cb44b89e85f6922684b9e7a956ff05d53 100644 (file)
@@ -70,7 +70,8 @@ package Ada.Containers.Red_Black_Trees.Generic_Bounded_Operations is
    function Max (Tree : Tree_Type'Class; Node : Count_Type) return Count_Type;
    --  Returns the largest-valued node of the subtree rooted at Node
 
-   function Vet (Tree : Tree_Type'Class; Index : Count_Type) return Boolean;
+   function Vet (Tree : Tree_Type'Class; Index : Count_Type) return Boolean
+     with Inline;
    --  Inspects Node to determine (to the extent possible) whether
    --  the node is valid; used to detect if the node is dangling.