public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Minor efficiency improvement in containers
@ 2021-05-07  9:38 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-07  9:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

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'.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1393 bytes --]

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;
 
       --------------



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-07  9:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07  9:38 [Ada] Minor efficiency improvement in containers Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).