public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Avoid repeated calls when looking for first/last slocs of a node
@ 2023-05-22  8:51 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-05-22  8:51 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

From: Piotr Trojanek <trojanek@adacore.com>

gcc/ada/

	* errout.adb (First_Loc): Avoid repeated calls.
	(Last_Loc): Likewise.

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

---
 gcc/ada/errout.adb | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 49281fdb05f..a82aff5266b 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -1845,11 +1845,12 @@ package body Errout is
    ----------------
 
    function First_Sloc (N : Node_Id) return Source_Ptr is
-      SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
-      SF : constant Source_Ptr        := Source_First (SI);
-      SL : constant Source_Ptr        := Source_Last (SI);
-      F  : Node_Id;
-      S  : Source_Ptr;
+      SI  : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
+      SF  : constant Source_Ptr        := Source_First (SI);
+      SL  : constant Source_Ptr        := Source_Last (SI);
+      Src : constant Source_Buffer_Ptr := Source_Text (SI);
+      F   : Node_Id;
+      S   : Source_Ptr;
 
    begin
       F := First_Node (N);
@@ -1876,11 +1877,11 @@ package body Errout is
             Search_Loop : for K in 1 .. 12 loop
                exit Search_Loop when S = SF;
 
-               if Source_Text (SI) (S - 1) = '(' then
+               if Src (S - 1) = '(' then
                   S := S - 1;
                   exit Search_Loop;
 
-               elsif Source_Text (SI) (S - 1) <= ' ' then
+               elsif Src (S - 1) <= ' ' then
                   S := S - 1;
 
                else
@@ -1963,11 +1964,12 @@ package body Errout is
    ---------------
 
    function Last_Sloc (N : Node_Id) return Source_Ptr is
-      SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
-      SF : constant Source_Ptr        := Source_First (SI);
-      SL : constant Source_Ptr        := Source_Last (SI);
-      F  : Node_Id;
-      S  : Source_Ptr;
+      SI  : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
+      SF  : constant Source_Ptr        := Source_First (SI);
+      SL  : constant Source_Ptr        := Source_Last (SI);
+      Src : constant Source_Buffer_Ptr := Source_Text (SI);
+      F   : Node_Id;
+      S   : Source_Ptr;
 
    begin
       F := Last_Node (N);
@@ -1980,7 +1982,7 @@ package body Errout is
       --  Skip past an identifier
 
       while S in SF .. SL - 1
-        and then Source_Text (SI) (S + 1)
+        and then Src (S + 1)
           in
         '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '.' | '_'
       loop
@@ -2000,11 +2002,11 @@ package body Errout is
             Search_Loop : for K in 1 .. 12 loop
                exit Node_Loop when S = SL;
 
-               if Source_Text (SI) (S + 1) = ')' then
+               if Src (S + 1) = ')' then
                   S := S + 1;
                   exit Search_Loop;
 
-               elsif Source_Text (SI) (S + 1) <= ' ' then
+               elsif Src (S + 1) <= ' ' then
                   S := S + 1;
 
                else
@@ -2021,7 +2023,7 @@ package body Errout is
       --  Remove any trailing space
 
       while S in SF + 1 .. SL
-        and then Source_Text (SI) (S) = ' '
+        and then Src (S) = ' '
       loop
          S := S - 1;
       end loop;
-- 
2.40.0


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

only message in thread, other threads:[~2023-05-22  8:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-22  8:51 [COMMITTED] ada: Avoid repeated calls when looking for first/last slocs of a node 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).