public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Optimize performance and remove dynamic frame requirement.
@ 2023-12-19 14:30 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-12-19 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Vasiliy Fofanov

From: Vasiliy Fofanov <fofanov@adacore.com>

gcc/ada/

	* libgnat/i-cstrin.adb (Value): Optimize.

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

---
 gcc/ada/libgnat/i-cstrin.adb | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/libgnat/i-cstrin.adb b/gcc/ada/libgnat/i-cstrin.adb
index 1eb28655004..73a0bc875bd 100644
--- a/gcc/ada/libgnat/i-cstrin.adb
+++ b/gcc/ada/libgnat/i-cstrin.adb
@@ -346,11 +346,13 @@ is
    end Value;
 
    function Value (Item : chars_ptr; Length : size_t) return String is
-      Result : char_array (0 .. Length);
+      Result : String (1 .. Natural (Length));
+      C : char;
 
    begin
       pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
                        "early returns for performance");
+
       --  As per AI-00177, this is equivalent to:
 
       --    To_Ada (Value (Item, Length) & nul);
@@ -359,16 +361,17 @@ is
          raise Dereference_Error;
       end if;
 
-      for J in 0 .. Length - 1 loop
-         Result (J) := Peek (Item + J);
+      for J in Result'Range loop
+         C := Peek (Item + size_t (J - 1));
 
-         if Result (J) = nul then
-            return To_Ada (Result (0 .. J));
+         if C = nul then
+            return Result (1 .. J - 1);
+         else
+            Result (J) := To_Ada (C);
          end if;
       end loop;
 
-      Result (Length) := nul;
-      return To_Ada (Result);
+      return Result;
 
       pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
    end Value;
-- 
2.43.0


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

only message in thread, other threads:[~2023-12-19 14:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 14:30 [COMMITTED] ada: Optimize performance and remove dynamic frame requirement Marc Poulhiès

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