]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve Append performance for Ada.Containers.Bounded_Vectors
authorSteve Baird <baird@adacore.com>
Mon, 10 Nov 2025 22:36:33 +0000 (14:36 -0800)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 21 Nov 2025 08:29:36 +0000 (09:29 +0100)
In (any instance of) Ada.Containers.Bounded_Vectors, for the procedure
overload of Append that takes parameters of types Vector and Element_Type,
improve performance in the case where either of the GNAT-defined checks
Container_Checks or Tampering_Check are suppressed.

gcc/ada/ChangeLog:

* libgnat/a-cobove.adb
(Append): Add an equivalent fast path for the case where tampering
checks are suppressed.

gcc/ada/libgnat/a-cobove.adb

index 3b5b4a61bf5bd2fe46d164e257f89deb305ec9ae..6371fb57d28a2008946279c27f27bcde99914f0f 100644 (file)
@@ -363,7 +363,15 @@ package body Ada.Containers.Bounded_Vectors is
                      New_Item  :        Element_Type)
    is
    begin
-      Insert (Container, Last_Index (Container) + 1, New_Item, 1);
+      if T_Check then
+         --  handle the general case
+         Insert (Container, Last_Index (Container) + 1, New_Item, 1);
+      else
+         --  The fast path.
+         --  The first (but not the second) statement may fail a check.
+         Container.Elements (To_Array_Index (Container.Last) + 1) := New_Item;
+         Container.Last := Container.Last + 1;
+      end if;
    end Append;
 
    --------------