[Ada] Minor efficiency improvement in containers
authorBob Duff <duff@adacore.com>
Mon, 25 Jan 2021 15:18:08 +0000 (10:18 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 7 May 2021 09:28:54 +0000 (05:28 -0400)
gcc/ada/

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

gcc/ada/libgnat/a-conhel.adb

index 6092845..e7d82ac 100644 (file)
@@ -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;
 
       --------------