OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-strunb-shared.adb
index f4083b5..cf2582a 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -50,16 +50,6 @@ package body Ada.Strings.Unbounded is
    --  align the returned memory on the maximum alignment as malloc does not
    --  know the target alignment.
 
-   procedure Sync_Add_And_Fetch
-     (Ptr   : access Interfaces.Unsigned_32;
-      Value : Interfaces.Unsigned_32);
-   pragma Import (Intrinsic, Sync_Add_And_Fetch, "__sync_add_and_fetch_4");
-
-   function Sync_Sub_And_Fetch
-     (Ptr   : access Interfaces.Unsigned_32;
-      Value : Interfaces.Unsigned_32) return Interfaces.Unsigned_32;
-   pragma Import (Intrinsic, Sync_Sub_And_Fetch, "__sync_sub_and_fetch_4");
-
    function Aligned_Max_Length (Max_Length : Natural) return Natural;
    --  Returns recommended length of the shared string which is greater or
    --  equal to specified length. Calculation take in sense alignment of the
@@ -86,7 +76,7 @@ package body Ada.Strings.Unbounded is
          Reference (Empty_Shared_String'Access);
          DR := Empty_Shared_String'Access;
 
-      --  Left string is empty, return Rigth string
+      --  Left string is empty, return Right string
 
       elsif LR.Last = 0 then
          Reference (RR);
@@ -98,7 +88,7 @@ package body Ada.Strings.Unbounded is
          Reference (LR);
          DR := LR;
 
-      --  Overwise, allocate new shared string and fill data
+      --  Otherwise, allocate new shared string and fill data
 
       else
          DR := Allocate (LR.Last + RR.Last);
@@ -633,12 +623,10 @@ package body Ada.Strings.Unbounded is
 
    function Can_Be_Reused
      (Item   : Shared_String_Access;
-      Length : Natural) return Boolean
-   is
-      use Interfaces;
+      Length : Natural) return Boolean is
    begin
       return
-        Item.Counter = 1
+        System.Atomic_Counters.Is_One (Item.Counter)
           and then Item.Max_Length >= Length
           and then Item.Max_Length <=
                      Aligned_Max_Length (Length + Length / Growth_Factor);
@@ -819,6 +807,19 @@ package body Ada.Strings.Unbounded is
    procedure Find_Token
      (Source : Unbounded_String;
       Set    : Maps.Character_Set;
+      From   : Positive;
+      Test   : Strings.Membership;
+      First  : out Positive;
+      Last   : out Natural)
+   is
+      SR : constant Shared_String_Access := Source.Reference;
+   begin
+      Search.Find_Token (SR.Data (From .. SR.Last), Set, Test, First, Last);
+   end Find_Token;
+
+   procedure Find_Token
+     (Source : Unbounded_String;
+      Set    : Maps.Character_Set;
       Test   : Strings.Membership;
       First  : out Positive;
       Last   : out Natural)
@@ -1269,7 +1270,7 @@ package body Ada.Strings.Unbounded is
 
    procedure Reference (Item : not null Shared_String_Access) is
    begin
-      Sync_Add_And_Fetch (Item.Counter'Access, 1);
+      System.Atomic_Counters.Increment (Item.Counter);
    end Reference;
 
    ---------------------
@@ -1285,7 +1286,7 @@ package body Ada.Strings.Unbounded is
       DR : Shared_String_Access;
 
    begin
-      --  Bounds check.
+      --  Bounds check
 
       if Index <= SR.Last then
 
@@ -1334,7 +1335,9 @@ package body Ada.Strings.Unbounded is
       --  Do replace operation when removed slice is not empty
 
       if High >= Low then
-         DL := By'Length + SR.Last + Low - High - 1;
+         DL := By'Length + SR.Last + Low - Integer'Min (High, SR.Last) - 1;
+         --  This is the number of characters remaining in the string after
+         --  replacing the slice.
 
          --  Result is empty string, reuse empty shared string
 
@@ -1381,7 +1384,9 @@ package body Ada.Strings.Unbounded is
       --  Do replace operation only when replaced slice is not empty
 
       if High >= Low then
-         DL := By'Length + SR.Last + Low - High - 1;
+         DL := By'Length + SR.Last + Low - Integer'Min (High, SR.Last) - 1;
+         --  This is the number of characters remaining in the string after
+         --  replacing the slice.
 
          --  Result is empty string, reuse empty shared string
 
@@ -2065,7 +2070,6 @@ package body Ada.Strings.Unbounded is
    -----------------
 
    procedure Unreference (Item : not null Shared_String_Access) is
-      use Interfaces;
 
       procedure Free is
         new Ada.Unchecked_Deallocation (Shared_String, Shared_String_Access);
@@ -2073,7 +2077,7 @@ package body Ada.Strings.Unbounded is
       Aux : Shared_String_Access := Item;
 
    begin
-      if Sync_Sub_And_Fetch (Aux.Counter'Access, 1) = 0 then
+      if System.Atomic_Counters.Decrement (Aux.Counter) then
 
          --  Reference counter of Empty_Shared_String must never reach zero