[Ada] Minor efficiency improvement in containers

Message ID 20210507093822.GA140583@adacore.com
State New
Headers show
Series
  • [Ada] Minor efficiency improvement in containers
Related show

Commit Message

Pierre-Marie de Rodat May 7, 2021, 9:38 a.m.
Move an assertion to be conditional on T_Check, so pragma Suppress
(Tampering_Checks) will suppress it.  Note that the Lock component being
checked has the Atomic aspect. This is not a bug fix.

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

gcc/ada/

	* libgnat/a-conhel.adb (TC_Check): Move the Assert into the
	'if'.

Patch

diff --git a/gcc/ada/libgnat/a-conhel.adb b/gcc/ada/libgnat/a-conhel.adb
--- a/gcc/ada/libgnat/a-conhel.adb
+++ b/gcc/ada/libgnat/a-conhel.adb
@@ -122,17 +122,20 @@  package body Ada.Containers.Helpers is
 
       procedure TC_Check (T_Counts : Tamper_Counts) is
       begin
-         if T_Check and then T_Counts.Busy > 0 then
-            raise Program_Error with
-              "attempt to tamper with cursors";
+         if T_Check then
+            if T_Counts.Busy > 0 then
+               raise Program_Error with
+                 "attempt to tamper with cursors";
+            end if;
+
+            --  The lock status (which monitors "element tampering") always
+            --  implies that the busy status (which monitors "cursor
+            --  tampering") is set too; this is a representation invariant.
+            --  Thus if the busy count is zero, then the lock count
+            --  must also be zero.
+
+            pragma Assert (T_Counts.Lock = 0);
          end if;
-
-         --  The lock status (which monitors "element tampering") always
-         --  implies that the busy status (which monitors "cursor tampering")
-         --  is set too; this is a representation invariant. Thus if the busy
-         --  bit is not set, then the lock bit must not be set either.
-
-         pragma Assert (T_Counts.Lock = 0);
       end TC_Check;
 
       --------------