From 8f6a053b80195fbd4cdc65cf7c18b95f3f8feb85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerardo=20Garc=C3=ADa=20Pe=C3=B1a?= Date: Wed, 3 Apr 2013 17:24:35 +0200 Subject: [PATCH] Refactorized Convert(char[], int, ...) to use the pointer version. --- mcs/class/corlib/System.Text/Encoder.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mcs/class/corlib/System.Text/Encoder.cs b/mcs/class/corlib/System.Text/Encoder.cs index 9082efc24ff..e44bb939048 100644 --- a/mcs/class/corlib/System.Text/Encoder.cs +++ b/mcs/class/corlib/System.Text/Encoder.cs @@ -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) -- 2.25.1