Merge pull request #2353 from ludovic-henry/fix-servicemodel-15153
[mono.git] / mcs / class / corlib / ReferenceSources / String.cs
index d4cec69780f1227be6dc612888810dc2e92da8e6..78cd58f81a89c863c60a9a9e4088d312b35c0828 100644 (file)
@@ -324,9 +324,23 @@ namespace System
                        }
                }
 
-        internal static int nativeCompareOrdinalEx (String strA, int indexA, String strB, int indexB, int count)
-        {
-               return CompareOrdinalUnchecked (strA, indexA, count, strB, indexB, count);
+               internal static int nativeCompareOrdinalEx (String strA, int indexA, String strB, int indexB, int count)
+               {
+                       //
+                       // .net does following checks in unmanaged land only which is quite
+                       // wrong as it's not always necessary and argument names don't match
+                       // but we are compatible
+                       //
+                       if (count < 0)
+                               throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
+
+                       if (indexA < 0 || indexA > strA.Length)
+                               throw new ArgumentOutOfRangeException("indexA", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+
+                       if (indexB < 0 || indexB > strB.Length)
+                               throw new ArgumentOutOfRangeException("indexB", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+
+                       return CompareOrdinalUnchecked (strA, indexA, count, strB, indexB, count);
         }
 
                unsafe String ReplaceInternal (char oldChar, char newChar)
@@ -365,7 +379,7 @@ namespace System
                        return tmp;
                }
 
-               public String ReplaceInternal (String oldValue, String newValue)
+               internal String ReplaceInternal (String oldValue, String newValue)
                {
                        // LAMESPEC: According to MSDN the following method is culture-sensitive but this seems to be incorrect
                        // LAMESPEC: Result is undefined if result Length is longer than maximum string Length
@@ -611,6 +625,44 @@ namespace System
                {
                        Buffer.Memcpy (dest, src, size);
                }
+
+               /* Used by the runtime */
+               internal static unsafe void bzero (byte *dest, int len) {
+                       memset (dest, 0, len);
+               }
+
+               internal static unsafe void bzero_aligned_1 (byte *dest, int len) {
+                       ((byte*)dest) [0] = 0;
+               }
+
+               internal static unsafe void bzero_aligned_2 (byte *dest, int len) {
+                       ((short*)dest) [0] = 0;
+               }
+
+               internal static unsafe void bzero_aligned_4 (byte *dest, int len) {
+                       ((int*)dest) [0] = 0;
+               }
+
+               internal static unsafe void bzero_aligned_8 (byte *dest, int len) {
+                       ((long*)dest) [0] = 0;
+               }
+
+               internal static unsafe void memcpy_aligned_1 (byte *dest, byte *src, int size) {
+                       ((byte*)dest) [0] = ((byte*)src) [0];
+               }
+
+               internal static unsafe void memcpy_aligned_2 (byte *dest, byte *src, int size) {
+                       ((short*)dest) [0] = ((short*)src) [0];
+               }
+
+               internal static unsafe void memcpy_aligned_4 (byte *dest, byte *src, int size) {
+                       ((int*)dest) [0] = ((int*)src) [0];
+               }
+
+               internal static unsafe void memcpy_aligned_8 (byte *dest, byte *src, int size) {
+                       ((long*)dest) [0] = ((long*)src) [0];
+               }
+
                #endregion
 
                // Certain constructors are redirected to CreateString methods with
@@ -641,74 +693,22 @@ namespace System
 
                unsafe string CreateString (char *value)
                {
-                       if (value == null)
-                               return Empty;
-                       char *p = value;
-                       int i = 0;
-                       while (*p != 0) {
-                               ++i;
-                               ++p;
-                       }
-                       string result = FastAllocateString (i);
-
-                       if (i != 0) {
-                               fixed (char *dest = result) {
-                                       CharCopy (dest, value, i);
-                               }
-                       }
-                       return result;
+                       return CtorCharPtr (value);
                }
 
                unsafe string CreateString (char *value, int startIndex, int length)
                {
-                       if (length == 0)
-                               return Empty;
-                       if (value == null)
-                               throw new ArgumentNullException ("value");
-                       if (startIndex < 0)
-                               throw new ArgumentOutOfRangeException ("startIndex");
-                       if (length < 0)
-                               throw new ArgumentOutOfRangeException ("length");
-
-                       string result = FastAllocateString (length);
-
-                       fixed (char *dest = result) {
-                               CharCopy (dest, value + startIndex, length);
-                       }
-                       return result;
+                       return CtorCharPtrStartLength (value, startIndex, length);
                }
 
-               unsafe string CreateString (char [] val, int startIndex, int length)
+               string CreateString (char [] val, int startIndex, int length)
                {
-                       if (val == null)
-                               throw new ArgumentNullException ("value");
-                       if (startIndex < 0)
-                               throw new ArgumentOutOfRangeException ("startIndex", "Cannot be negative.");
-                       if (length < 0)
-                               throw new ArgumentOutOfRangeException ("length", "Cannot be negative.");
-                       if (startIndex > val.Length - length)
-                               throw new ArgumentOutOfRangeException ("startIndex", "Cannot be negative, and should be less than length of string.");
-                       if (length == 0)
-                               return Empty;
-
-                       string result = FastAllocateString (length);
-
-                       fixed (char *dest = result, src = val) {
-                               CharCopy (dest, src + startIndex, length);
-                       }
-                       return result;
+                       return CtorCharArrayStartLength (val, startIndex, length);
                }
 
-               unsafe string CreateString (char [] val)
+               string CreateString (char [] val)
                {
-                       if (val == null || val.Length == 0)
-                               return Empty;
-                       string result = FastAllocateString (val.Length);
-
-                       fixed (char *dest = result, src = val) {
-                               CharCopy (dest, src, val.Length);
-                       }
-                       return result;
+                       return CtorCharArray (val);
                }
 
                unsafe string CreateString (char c, int count)