diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2023-02-09 19:20:14 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-22 10:46:13 +0200 |
commit | 014f7f3a7075be6e6d02186f4aad53200ebaafa8 (patch) | |
tree | 2adabb04bfd2fb68e9c8a447068beed21fd22a8b | |
parent | 8911204d4ab366d61c24ed8da9557fcf4c40e4bc (diff) | |
download | gcc-014f7f3a7075be6e6d02186f4aad53200ebaafa8.zip gcc-014f7f3a7075be6e6d02186f4aad53200ebaafa8.tar.gz gcc-014f7f3a7075be6e6d02186f4aad53200ebaafa8.tar.bz2 |
ada: Avoid repeated calls when looking for first/last slocs of a node
gcc/ada/
* errout.adb (First_Loc): Avoid repeated calls.
(Last_Loc): Likewise.
-rw-r--r-- | gcc/ada/errout.adb | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 49281fd..a82aff5 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; |