public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-396] ada: Refactor GNAT.Directory_Operations.Read to minimise runtime checks
@ 2024-05-13 8:35 Marc Poulhi?s
0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-13 8:35 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:105bba84b10625848ca39a26a42deaa1b2783d71
commit r15-396-g105bba84b10625848ca39a26a42deaa1b2783d71
Author: Piotr Trojanek <trojanek@adacore.com>
Date: Tue Jun 14 13:08:38 2022 +0200
ada: Refactor GNAT.Directory_Operations.Read to minimise runtime checks
Array assignments are likely more efficient than element-by-element
copying; in particular, they avoid constraints checks in every iteration
of a loop (when the runtime is compiled with checks enabled).
A cleanup and improvement opportunity spotted while working on improved
detection of uninitialised local scalar objects.
gcc/ada/
* libgnat/g-dirope.adb (Read): Use null-excluding,
access-to-constant type; replace element-by-element copy with
array assignments.
Diff:
---
gcc/ada/libgnat/g-dirope.adb | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/gcc/ada/libgnat/g-dirope.adb b/gcc/ada/libgnat/g-dirope.adb
index c23aa68b700f..428d27d9e8de 100644
--- a/gcc/ada/libgnat/g-dirope.adb
+++ b/gcc/ada/libgnat/g-dirope.adb
@@ -676,13 +676,9 @@ package body GNAT.Directory_Operations is
return;
end if;
- Last :=
- (if Str'Length > Filename_Len then Str'First + Filename_Len - 1
- else Str'Last);
-
declare
subtype Path_String is String (1 .. Filename_Len);
- type Path_String_Access is access Path_String;
+ type Path_String_Access is not null access constant Path_String;
function Address_To_Access is new
Ada.Unchecked_Conversion
@@ -693,9 +689,13 @@ package body GNAT.Directory_Operations is
Address_To_Access (Filename_Addr);
begin
- for J in Str'First .. Last loop
- Str (J) := Path_Access (J - Str'First + 1);
- end loop;
+ if Str'Length > Filename_Len then
+ Last := Str'First + Filename_Len - 1;
+ Str (Str'First .. Last) := Path_Access.all;
+ else
+ Last := Str'Last;
+ Str := Path_Access (1 .. Str'Length);
+ end if;
end;
end Read;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-13 8:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 8:35 [gcc r15-396] ada: Refactor GNAT.Directory_Operations.Read to minimise runtime checks 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).