diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-15 15:52:27 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-15 15:52:27 +0000 |
commit | 20e42bc1b770789e9db37f51ca755d305f5b2eec (patch) | |
tree | 7a7289c9b2877f87a4a78f1c91b483f803aa6e9f /gcc/ada/a-stzunb.adb | |
parent | 57b5da613404a43f2a614b15f24ce6cfb365d601 (diff) | |
download | gcc-20e42bc1b770789e9db37f51ca755d305f5b2eec.tar.gz |
2005-03-08 Robert Dewar <dewar@adacore.com>
* a-stzunb.adb, a-stzunb.adb a-stzunb.ads, a-stzunb.ads,
a-stwiun.ads, a-stwiun.adb, a-strunb.ads, a-strunb.adb: Move
Realloc_For_Chunk to private part of package.
New subprograms for AI-301
* a-szuzti.adb, a-suteio.adb, a-swuwti.adb: Improve efficiency of
Get_Line procedure.
Avoid unnecessary use of Get/Set_Wide_String
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96487 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-stzunb.adb')
-rw-r--r-- | gcc/ada/a-stzunb.adb | 259 |
1 files changed, 178 insertions, 81 deletions
diff --git a/gcc/ada/a-stzunb.adb b/gcc/ada/a-stzunb.adb index c6c5c4a9bd8..8717bb37577 100644 --- a/gcc/ada/a-stzunb.adb +++ b/gcc/ada/a-stzunb.adb @@ -39,16 +39,6 @@ package body Ada.Strings.Wide_Wide_Unbounded is use Ada.Finalization; - procedure Realloc_For_Chunk - (Source : in out Unbounded_Wide_Wide_String; - Chunk_Size : Natural); - pragma Inline (Realloc_For_Chunk); - -- Adjust the size allocated for the string. Add at least Chunk_Size so it - -- is safe to add a string of this size at the end of the current content. - -- The real size allocated for the string is Chunk_Size + x of the current - -- string size. This buffered handling makes the Append unbounded wide - -- string routines very fast. - --------- -- "&" -- --------- @@ -142,7 +132,6 @@ package body Ada.Strings.Wide_Wide_Unbounded is Result.Reference (1) := Left; Result.Reference (2 .. Result.Last) := Right.Reference (1 .. Right.Last); - return Result; end "&"; @@ -157,7 +146,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is Result : Unbounded_Wide_Wide_String; begin - Result.Last := Left; + Result.Last := Left; Result.Reference := new Wide_Wide_String (1 .. Left); for J in Result.Reference'Range loop @@ -195,7 +184,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is is Len : constant Natural := Right.Last; K : Positive; - Result : Unbounded_Wide_Wide_String; + Result : Unbounded_Wide_Wide_String; begin Result.Last := Left * Len; @@ -203,7 +192,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is Result.Reference := new Wide_Wide_String (1 .. Result.Last); K := 1; - for I in 1 .. Left loop + for J in 1 .. Left loop Result.Reference (K .. K + Len - 1) := Right.Reference (1 .. Right.Last); K := K + Len; @@ -417,11 +406,13 @@ package body Ada.Strings.Wide_Wide_Unbounded is (Source : Unbounded_Wide_Wide_String; Pattern : Wide_Wide_String; Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := - Wide_Wide_Maps.Identity) return Natural + Wide_Wide_Maps.Identity) + return Natural is begin - return Wide_Wide_Search.Count - (Source.Reference (1 .. Source.Last), Pattern, Mapping); + return + Wide_Wide_Search.Count + (Source.Reference (1 .. Source.Last), Pattern, Mapping); end Count; function Count @@ -431,8 +422,9 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Natural is begin - return Wide_Wide_Search.Count - (Source.Reference (1 .. Source.Last), Pattern, Mapping); + return + Wide_Wide_Search.Count + (Source.Reference (1 .. Source.Last), Pattern, Mapping); end Count; function Count @@ -440,8 +432,9 @@ package body Ada.Strings.Wide_Wide_Unbounded is Set : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural is begin - return Wide_Wide_Search.Count - (Source.Reference (1 .. Source.Last), Set); + return + Wide_Wide_Search.Count + (Source.Reference (1 .. Source.Last), Set); end Count; ------------ @@ -454,9 +447,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is Through : Natural) return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Delete - (Source.Reference (1 .. Source.Last), From, Through)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Delete + (Source.Reference (1 .. Source.Last), From, Through)); end Delete; procedure Delete @@ -506,7 +500,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is procedure Finalize (Object : in out Unbounded_Wide_Wide_String) is procedure Deallocate is new Ada.Unchecked_Deallocation - (Wide_Wide_String, Wide_Wide_String_Access); + (Wide_Wide_String, Wide_Wide_String_Access); begin -- Note: Don't try to free statically allocated null string @@ -514,6 +508,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is if Object.Reference /= Null_Wide_Wide_String'Access then Deallocate (Object.Reference); Object.Reference := Null_Unbounded_Wide_Wide_String.Reference; + Object.Last := 0; end if; end Finalize; @@ -540,7 +535,8 @@ package body Ada.Strings.Wide_Wide_Unbounded is procedure Free (X : in out Wide_Wide_String_Access) is procedure Deallocate is new Ada.Unchecked_Deallocation - (Wide_Wide_String, Wide_Wide_String_Access); + (Wide_Wide_String, Wide_Wide_String_Access); + begin -- Note: Do not try to free statically allocated null string @@ -560,10 +556,9 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Unbounded_Wide_Wide_String is begin - return - To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Head - (Source.Reference (1 .. Source.Last), Count, Pad)); + return To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Head + (Source.Reference (1 .. Source.Last), Count, Pad)); end Head; procedure Head @@ -572,11 +567,11 @@ package body Ada.Strings.Wide_Wide_Unbounded is Pad : Wide_Wide_Character := Wide_Wide_Space) is Old : Wide_Wide_String_Access := Source.Reference; - begin - Source.Reference := new Wide_Wide_String' - (Wide_Wide_Fixed.Head - (Source.Reference (1 .. Source.Last), Count, Pad)); + Source.Reference := + new Wide_Wide_String' + (Wide_Wide_Fixed.Head + (Source.Reference (1 .. Source.Last), Count, Pad)); Source.Last := Source.Reference'Length; Free (Old); end Head; @@ -590,11 +585,13 @@ package body Ada.Strings.Wide_Wide_Unbounded is Pattern : Wide_Wide_String; Going : Strings.Direction := Strings.Forward; Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := - Wide_Wide_Maps.Identity) return Natural + Wide_Wide_Maps.Identity) + return Natural is begin - return Wide_Wide_Search.Index - (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping); + return + Wide_Wide_Search.Index + (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping); end Index; function Index @@ -605,8 +602,9 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Natural is begin - return Wide_Wide_Search.Index - (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping); + return + Wide_Wide_Search.Index + (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping); end Index; function Index @@ -620,13 +618,68 @@ package body Ada.Strings.Wide_Wide_Unbounded is (Source.Reference (1 .. Source.Last), Set, Test, Going); end Index; + function Index + (Source : Unbounded_Wide_Wide_String; + Pattern : Wide_Wide_String; + From : Positive; + Going : Direction := Forward; + Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := + Wide_Wide_Maps.Identity) + return Natural + is + begin + return + Wide_Wide_Search.Index + (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping); + end Index; + + function Index + (Source : Unbounded_Wide_Wide_String; + Pattern : Wide_Wide_String; + From : Positive; + Going : Direction := Forward; + Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) + return Natural + is + begin + return + Wide_Wide_Search.Index + (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping); + end Index; + + + function Index + (Source : Unbounded_Wide_Wide_String; + Set : Wide_Wide_Maps.Wide_Wide_Character_Set; + From : Positive; + Test : Membership := Inside; + Going : Direction := Forward) return Natural + is + begin + return + Wide_Wide_Search.Index + (Source.Reference (1 .. Source.Last), Set, From, Test, Going); + end Index; + function Index_Non_Blank (Source : Unbounded_Wide_Wide_String; Going : Strings.Direction := Strings.Forward) return Natural is begin - return Wide_Wide_Search.Index_Non_Blank - (Source.Reference (1 .. Source.Last), Going); + return + Wide_Wide_Search.Index_Non_Blank + (Source.Reference (1 .. Source.Last), Going); + end Index_Non_Blank; + + function Index_Non_Blank + (Source : Unbounded_Wide_Wide_String; + From : Positive; + Going : Direction := Forward) return Natural + is + begin + return + Wide_Wide_Search.Index_Non_Blank + (Source.Reference (1 .. Source.Last), From, Going); end Index_Non_Blank; ---------------- @@ -649,9 +702,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Insert - (Source.Reference (1 .. Source.Last), Before, New_Item)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Insert + (Source.Reference (1 .. Source.Last), Before, New_Item)); end Insert; procedure Insert @@ -693,9 +747,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Overwrite - (Source.Reference (1 .. Source.Last), Position, New_Item)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Overwrite + (Source.Reference (1 .. Source.Last), Position, New_Item)); end Overwrite; procedure Overwrite @@ -704,15 +759,12 @@ package body Ada.Strings.Wide_Wide_Unbounded is New_Item : Wide_Wide_String) is NL : constant Natural := New_Item'Length; - begin if Position <= Source.Last - NL + 1 then Source.Reference (Position .. Position + NL - 1) := New_Item; - else declare Old : Wide_Wide_String_Access := Source.Reference; - begin Source.Reference := new Wide_Wide_String' (Wide_Wide_Fixed.Overwrite @@ -740,7 +792,6 @@ package body Ada.Strings.Wide_Wide_Unbounded is Alloc_Chunk_Size : constant Positive := Chunk_Size + (S_Length / Growth_Factor); Tmp : Wide_Wide_String_Access; - begin Tmp := new Wide_Wide_String (1 .. S_Length + Alloc_Chunk_Size); Tmp (1 .. Source.Last) := Source.Reference (1 .. Source.Last); @@ -778,20 +829,18 @@ package body Ada.Strings.Wide_Wide_Unbounded is By : Wide_Wide_String) return Unbounded_Wide_Wide_String is begin - return - To_Unbounded_Wide_Wide_String + return To_Unbounded_Wide_Wide_String (Wide_Wide_Fixed.Replace_Slice (Source.Reference (1 .. Source.Last), Low, High, By)); end Replace_Slice; procedure Replace_Slice - (Source : in out Unbounded_Wide_Wide_String; - Low : Positive; - High : Natural; - By : Wide_Wide_String) + (Source : in out Unbounded_Wide_Wide_String; + Low : Positive; + High : Natural; + By : Wide_Wide_String) is Old : Wide_Wide_String_Access := Source.Reference; - begin Source.Reference := new Wide_Wide_String' (Wide_Wide_Fixed.Replace_Slice @@ -800,6 +849,20 @@ package body Ada.Strings.Wide_Wide_Unbounded is Free (Old); end Replace_Slice; + ------------------------------------ + -- Set_Unbounded_Wide_Wide_String -- + ------------------------------------ + + procedure Set_Unbounded_Wide_Wide_String + (Target : out Unbounded_Wide_Wide_String; + Source : Wide_Wide_String) + is + begin + Target.Last := Source'Length; + Target.Reference := new Wide_Wide_String (1 .. Source'Length); + Target.Reference.all := Source; + end Set_Unbounded_Wide_Wide_String; + ----------- -- Slice -- ----------- @@ -814,7 +877,6 @@ package body Ada.Strings.Wide_Wide_Unbounded is if Low > Source.Last + 1 or else High > Source.Last then raise Index_Error; - else return Source.Reference (Low .. High); end if; @@ -828,8 +890,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is (Source : Unbounded_Wide_Wide_String; Count : Natural; Pad : Wide_Wide_Character := Wide_Wide_Space) - return Unbounded_Wide_Wide_String - is + return Unbounded_Wide_Wide_String is begin return To_Unbounded_Wide_Wide_String (Wide_Wide_Fixed.Tail @@ -842,7 +903,6 @@ package body Ada.Strings.Wide_Wide_Unbounded is Pad : Wide_Wide_Character := Wide_Wide_Space) is Old : Wide_Wide_String_Access := Source.Reference; - begin Source.Reference := new Wide_Wide_String' (Wide_Wide_Fixed.Tail @@ -876,7 +936,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Result; end To_Unbounded_Wide_Wide_String; - -------------------- + ------------------- -- To_Wide_Wide_String -- -------------------- @@ -887,6 +947,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Source.Reference (1 .. Source.Last); end To_Wide_Wide_String; + --------------- -- Translate -- --------------- @@ -897,9 +958,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Translate - (Source.Reference (1 .. Source.Last), Mapping)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Translate + (Source.Reference (1 .. Source.Last), Mapping)); end Translate; procedure Translate @@ -907,8 +969,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping) is begin - Wide_Wide_Fixed.Translate - (Source.Reference (1 .. Source.Last), Mapping); + Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping); end Translate; function Translate @@ -917,9 +978,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Translate - (Source.Reference (1 .. Source.Last), Mapping)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Translate + (Source.Reference (1 .. Source.Last), Mapping)); end Translate; procedure Translate @@ -927,8 +989,7 @@ package body Ada.Strings.Wide_Wide_Unbounded is Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) is begin - Wide_Wide_Fixed.Translate - (Source.Reference (1 .. Source.Last), Mapping); + Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping); end Translate; ---------- @@ -940,8 +1001,9 @@ package body Ada.Strings.Wide_Wide_Unbounded is Side : Trim_End) return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side)); end Trim; procedure Trim @@ -964,9 +1026,10 @@ package body Ada.Strings.Wide_Wide_Unbounded is return Unbounded_Wide_Wide_String is begin - return To_Unbounded_Wide_Wide_String - (Wide_Wide_Fixed.Trim - (Source.Reference (1 .. Source.Last), Left, Right)); + return + To_Unbounded_Wide_Wide_String + (Wide_Wide_Fixed.Trim + (Source.Reference (1 .. Source.Last), Left, Right)); end Trim; procedure Trim @@ -976,11 +1039,45 @@ package body Ada.Strings.Wide_Wide_Unbounded is is Old : Wide_Wide_String_Access := Source.Reference; begin - Source.Reference := new Wide_Wide_String' - (Wide_Wide_Fixed.Trim - (Source.Reference (1 .. Source.Last), Left, Right)); + Source.Reference := + new Wide_Wide_String' + (Wide_Wide_Fixed.Trim + (Source.Reference (1 .. Source.Last), Left, Right)); Source.Last := Source.Reference'Length; Free (Old); end Trim; + --------------------- + -- Unbounded_Slice -- + --------------------- + + function Unbounded_Slice + (Source : Unbounded_Wide_Wide_String; + Low : Positive; + High : Natural) return Unbounded_Wide_Wide_String + is + begin + if Low > Source.Last + 1 or else High > Source.Last then + raise Index_Error; + else + return + To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High)); + end if; + end Unbounded_Slice; + + procedure Unbounded_Slice + (Source : Unbounded_Wide_Wide_String; + Target : out Unbounded_Wide_Wide_String; + Low : Positive; + High : Natural) + is + begin + if Low > Source.Last + 1 or else High > Source.Last then + raise Index_Error; + else + Target := + To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High)); + end if; + end Unbounded_Slice; + end Ada.Strings.Wide_Wide_Unbounded; |