From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 76D8F398702F; Fri, 9 Jul 2021 12:38:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76D8F398702F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2204] [Ada] Code cleanups in a-strfix.adb X-Act-Checkin: gcc X-Git-Author: Arnaud Charlet X-Git-Refname: refs/heads/master X-Git-Oldrev: 2a847e8c8fa3523ac8bfb3e20600dce6addcd7f9 X-Git-Newrev: e4a6acd67ef7ab110b7f575b22019554819af0cc Message-Id: <20210709123853.76D8F398702F@sourceware.org> Date: Fri, 9 Jul 2021 12:38:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jul 2021 12:38:53 -0000 https://gcc.gnu.org/g:e4a6acd67ef7ab110b7f575b22019554819af0cc commit r12-2204-ge4a6acd67ef7ab110b7f575b22019554819af0cc Author: Arnaud Charlet Date: Wed Jun 9 11:58:47 2021 -0400 [Ada] Code cleanups in a-strfix.adb gcc/ada/ * libgnat/a-strfix.adb: Take advantage of extended returns. Diff: --- gcc/ada/libgnat/a-strfix.adb | 138 +++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 84 deletions(-) diff --git a/gcc/ada/libgnat/a-strfix.adb b/gcc/ada/libgnat/a-strfix.adb index 8b7f043d47c..ee72b6b4fbc 100644 --- a/gcc/ada/libgnat/a-strfix.adb +++ b/gcc/ada/libgnat/a-strfix.adb @@ -145,30 +145,26 @@ package body Ada.Strings.Fixed is (Left : Natural; Right : Character) return String is - Result : String (1 .. Left); - begin - for J in Result'Range loop - Result (J) := Right; - end loop; - - return Result; + return Result : String (1 .. Left) do + for J in Result'Range loop + Result (J) := Right; + end loop; + end return; end "*"; function "*" (Left : Natural; Right : String) return String is - Result : String (1 .. Left * Right'Length); Ptr : Integer := 1; - begin - for J in 1 .. Left loop - Result (Ptr .. Ptr + Right'Length - 1) := Right; - Ptr := Ptr + Right'Length; - end loop; - - return Result; + return Result : String (1 .. Left * Right'Length) do + for J in 1 .. Left loop + Result (Ptr .. Ptr + Right'Length - 1) := Right; + Ptr := Ptr + Right'Length; + end loop; + end return; end "*"; ------------ @@ -180,6 +176,7 @@ package body Ada.Strings.Fixed is From : Positive; Through : Natural) return String is + Front : Integer; begin if From > Through then declare @@ -207,18 +204,13 @@ package body Ada.Strings.Fixed is end if; else - declare - Front : constant Integer := From - Source'First; - Result : String (1 .. Source'Length - (Through - From + 1)); - - begin + Front := From - Source'First; + return Result : String (1 .. Source'Length - (Through - From + 1)) do Result (1 .. Front) := Source (Source'First .. From - 1); Result (Front + 1 .. Result'Last) := Source (Through + 1 .. Source'Last); - - return Result; - end; + end return; end if; end Delete; @@ -253,18 +245,13 @@ package body Ada.Strings.Fixed is Result_Type (Source (Source'First .. Source'First + Count - 1)); else - declare - Result : Result_Type; - - begin + return Result : Result_Type do Result (1 .. Source'Length) := Source; for J in Source'Length + 1 .. Count loop Result (J) := Pad; end loop; - - return Result; - end; + end return; end if; end Head; @@ -291,7 +278,6 @@ package body Ada.Strings.Fixed is Before : Positive; New_Item : String) return String is - Result : String (1 .. Source'Length + New_Item'Length); Front : constant Integer := Before - Source'First; begin @@ -299,14 +285,14 @@ package body Ada.Strings.Fixed is raise Index_Error; end if; - Result (1 .. Front) := - Source (Source'First .. Before - 1); - Result (Front + 1 .. Front + New_Item'Length) := - New_Item; - Result (Front + New_Item'Length + 1 .. Result'Last) := - Source (Before .. Source'Last); - - return Result; + return Result : String (1 .. Source'Length + New_Item'Length) do + Result (1 .. Front) := + Source (Source'First .. Before - 1); + Result (Front + 1 .. Front + New_Item'Length) := + New_Item; + Result (Front + New_Item'Length + 1 .. Result'Last) := + Source (Before .. Source'Last); + end return; end Insert; procedure Insert @@ -435,8 +421,7 @@ package body Ada.Strings.Fixed is function Overwrite (Source : String; Position : Positive; - New_Item : String) return String - is + New_Item : String) return String is begin if Position not in Source'First .. Source'Last + 1 then raise Index_Error; @@ -444,21 +429,17 @@ package body Ada.Strings.Fixed is declare Result_Length : constant Natural := - Integer'Max - (Source'Length, - Position - Source'First + New_Item'Length); - - Result : String (1 .. Result_Length); - Front : constant Integer := Position - Source'First; + Integer'Max (Source'Length, + Position - Source'First + New_Item'Length); + Front : constant Integer := Position - Source'First; begin - Result (1 .. Front) := - Source (Source'First .. Position - 1); - Result (Front + 1 .. Front + New_Item'Length) := - New_Item; - Result (Front + New_Item'Length + 1 .. Result'Length) := - Source (Position + New_Item'Length .. Source'Last); - return Result; + return Result : String (1 .. Result_Length) do + Result (1 .. Front) := Source (Source'First .. Position - 1); + Result (Front + 1 .. Front + New_Item'Length) := New_Item; + Result (Front + New_Item'Length + 1 .. Result'Length) := + Source (Position + New_Item'Length .. Source'Last); + end return; end; end Overwrite; @@ -495,24 +476,21 @@ package body Ada.Strings.Fixed is Integer'Max (0, Low - Source'First); -- Length of prefix of Source copied to result - Back_Len : constant Integer := - Integer'Max (0, Source'Last - High); + Back_Len : constant Integer := Integer'Max (0, Source'Last - High); -- Length of suffix of Source copied to result Result_Length : constant Integer := Front_Len + By'Length + Back_Len; -- Length of result - Result : String (1 .. Result_Length); - begin - Result (1 .. Front_Len) := Source (Source'First .. Low - 1); - Result (Front_Len + 1 .. Front_Len + By'Length) := By; - Result (Front_Len + By'Length + 1 .. Result'Length) := - Source (High + 1 .. Source'Last); - return Result; + return Result : String (1 .. Result_Length) do + Result (1 .. Front_Len) := Source (Source'First .. Low - 1); + Result (Front_Len + 1 .. Front_Len + By'Length) := By; + Result (Front_Len + By'Length + 1 .. Result'Length) := + Source (High + 1 .. Source'Last); + end return; end; - else return Insert (Source, Before => Low, New_Item => By); end if; @@ -549,17 +527,13 @@ package body Ada.Strings.Fixed is -- Pad on left else - declare - Result : Result_Type; - - begin + return Result : Result_Type do for J in 1 .. Count - Source'Length loop Result (J) := Pad; end loop; Result (Count - Source'Length + 1 .. Count) := Source; - return Result; - end; + end return; end if; end Tail; @@ -585,14 +559,12 @@ package body Ada.Strings.Fixed is (Source : String; Mapping : Maps.Character_Mapping) return String is - Result : String (1 .. Source'Length); - begin - for J in Source'Range loop - Result (J - (Source'First - 1)) := Value (Mapping, Source (J)); - end loop; - - return Result; + return Result : String (1 .. Source'Length) do + for J in Source'Range loop + Result (J - (Source'First - 1)) := Value (Mapping, Source (J)); + end loop; + end return; end Translate; procedure Translate @@ -609,15 +581,13 @@ package body Ada.Strings.Fixed is (Source : String; Mapping : Maps.Character_Mapping_Function) return String is - Result : String (1 .. Source'Length); pragma Unsuppress (Access_Check); - begin - for J in Source'Range loop - Result (J - (Source'First - 1)) := Mapping.all (Source (J)); - end loop; - - return Result; + return Result : String (1 .. Source'Length) do + for J in Source'Range loop + Result (J - (Source'First - 1)) := Mapping.all (Source (J)); + end loop; + end return; end Translate; procedure Translate