From: Steve Baird <[email protected]>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-cobove.adb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/a-cobove.adb b/gcc/ada/libgnat/a-cobove.adb
index 3b5b4a61bf5..6371fb57d28 100644
--- a/gcc/ada/libgnat/a-cobove.adb
+++ b/gcc/ada/libgnat/a-cobove.adb
@@ -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;
 
    --------------
-- 
2.51.0

Reply via email to