Refactorized Convert(char[], int, ...) to use the pointer version.
authorGerardo García Peña <killabytenow@gmail.com>
Wed, 3 Apr 2013 15:24:35 +0000 (17:24 +0200)
committerGerardo García Peña <killabytenow@gmail.com>
Wed, 3 Apr 2013 15:24:35 +0000 (17:24 +0200)
mcs/class/corlib/System.Text/Encoder.cs

index 9082efc24ffc13c35f92d63156fb4990cfdd3534..e44bb9390486d3f47001b83bf4e3fcb2b1d2fab0 100644 (file)
@@ -124,7 +124,7 @@ public abstract class Encoder
        }
 
        [ComVisible (false)]
-       public virtual void Convert (
+       public virtual unsafe void Convert (
                char [] chars, int charIndex, int charCount,
                byte [] bytes, int byteIndex, int byteCount, bool flush,
                out int charsUsed, out int bytesUsed, out bool completed)
@@ -142,16 +142,16 @@ public abstract class Encoder
                if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
                        throw new ArgumentOutOfRangeException ("byteCount");
 
-               charsUsed = charCount;
-               while (true) {
-                       bytesUsed = GetByteCount (chars, charIndex, charsUsed, flush);
-                       if (bytesUsed <= byteCount)
-                               break;
-                       flush = false;
-                       charsUsed >>= 1;
+               // refactorize passing control to byte* version
+               fixed (char* cptr = chars) {
+                       fixed (byte* bptr = bytes) {
+                               Convert(cptr + charIndex, charCount,
+                                       bptr + byteIndex, byteCount,
+                                       flush,
+                                       out charsUsed, out bytesUsed,
+                                       out completed);
+                       }
                }
-               completed = charsUsed == charCount;
-               bytesUsed = GetBytes (chars, charIndex, charsUsed, bytes, byteIndex, flush);
        }
 
        unsafe void CheckArguments (char* chars, int charCount, byte* bytes, int byteCount)