diff options
Diffstat (limited to 'gcc/ada/a-stwiun-shared.ads')
-rw-r--r-- | gcc/ada/a-stwiun-shared.ads | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gcc/ada/a-stwiun-shared.ads b/gcc/ada/a-stwiun-shared.ads index 988463e63d2..4c05d7309ec 100644 --- a/gcc/ada/a-stwiun-shared.ads +++ b/gcc/ada/a-stwiun-shared.ads @@ -410,10 +410,10 @@ private type Shared_Wide_String (Max_Length : Natural) is limited record Counter : System.Atomic_Counters.Atomic_Counter; - -- Reference counter. + -- Reference counter - Last : Natural := 0; - Data : Wide_String (1 .. Max_Length); + Last : Natural := 0; + Data : Wide_String (1 .. Max_Length); -- Last is the index of last significant element of the Data. All -- elements with larger indices are just an extra room. end record; @@ -424,8 +424,7 @@ private -- Increment reference counter. procedure Unreference (Item : not null Shared_Wide_String_Access); - -- Decrement reference counter. Deallocate Item when reference counter is - -- zero. + -- Decrement reference counter. Deallocate Item when ref counter is zero function Can_Be_Reused (Item : Shared_Wide_String_Access; @@ -445,7 +444,7 @@ private function To_Unbounded (S : Wide_String) return Unbounded_Wide_String renames To_Unbounded_Wide_String; - -- This renames are here only to be used in the pragma Stream_Convert. + -- This renames are here only to be used in the pragma Stream_Convert type Unbounded_Wide_String is new AF.Controlled with record Reference : Shared_Wide_String_Access := Empty_Shared_Wide_String'Access; @@ -453,22 +452,25 @@ private -- The Unbounded_Wide_String uses several techniques to increase speed of -- the application: + -- - implicit sharing or copy-on-write. Unbounded_Wide_String contains -- only the reference to the data which is shared between several -- instances. The shared data is reallocated only when its value is -- changed and the object mutation can't be used or it is inefficient to -- use it; + -- - object mutation. Shared data object can be reused without memory -- reallocation when all of the following requirements are meat: -- - shared data object don't used anywhere longer; -- - its size is sufficient to store new value; -- - the gap after reuse is less then some threshold. + -- - memory preallocation. Most of used memory allocation algorithms -- aligns allocated segment on the some boundary, thus some amount of -- additional memory can be preallocated without any impact. Such -- preallocated memory can used later by Append/Insert operations -- without reallocation. - -- + -- Reference counting uses GCC builtin atomic operations, which allows to -- safely share internal data between Ada tasks. Nevertheless, this not -- make objects of Unbounded_Wide_String thread-safe, so each instance @@ -485,7 +487,8 @@ private overriding procedure Finalize (Object : in out Unbounded_Wide_String); Null_Unbounded_Wide_String : constant Unbounded_Wide_String := - (AF.Controlled with - Reference => Empty_Shared_Wide_String'Access); + (AF.Controlled with + Reference => + Empty_Shared_Wide_String'Access); end Ada.Strings.Wide_Unbounded; |