From ab47c2281299f464ecddb1d04c292a37b96646dc Mon Sep 17 00:00:00 2001 From: James Ko Date: Mon, 4 Jul 2016 15:04:43 -0400 Subject: [PATCH] Use EncodingForwarder for GetChars(byte*, int, char*, int) --- src/mscorlib/src/System/Text/ASCIIEncoding.cs | 12 +----------- .../src/System/Text/EncodingForwarder.cs | 16 ++++++++++++++++ src/mscorlib/src/System/Text/EncodingNLS.cs | 12 +----------- src/mscorlib/src/System/Text/UTF32Encoding.cs | 12 +----------- src/mscorlib/src/System/Text/UTF7Encoding.cs | 12 +----------- src/mscorlib/src/System/Text/UTF8Encoding.cs | 12 +----------- src/mscorlib/src/System/Text/UnicodeEncoding.cs | 12 +----------- 7 files changed, 22 insertions(+), 66 deletions(-) diff --git a/src/mscorlib/src/System/Text/ASCIIEncoding.cs b/src/mscorlib/src/System/Text/ASCIIEncoding.cs index 267ccc7c2b44..d0472ee19bc8 100644 --- a/src/mscorlib/src/System/Text/ASCIIEncoding.cs +++ b/src/mscorlib/src/System/Text/ASCIIEncoding.cs @@ -179,17 +179,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [System.Runtime.InteropServices.ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of diff --git a/src/mscorlib/src/System/Text/EncodingForwarder.cs b/src/mscorlib/src/System/Text/EncodingForwarder.cs index deddad0e6af4..f7db5ec16a89 100644 --- a/src/mscorlib/src/System/Text/EncodingForwarder.cs +++ b/src/mscorlib/src/System/Text/EncodingForwarder.cs @@ -267,5 +267,21 @@ public unsafe static int GetChars(Encoding encoding, byte[] bytes, int byteIndex return encoding.GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, decoder: null); } } + + public unsafe static int GetChars(Encoding encoding, byte* bytes, int byteCount, char* chars, int charCount) + { + Contract.Assert(encoding != null); + if (bytes == null || chars == null) + { + throw new ArgumentNullException(bytes == null ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array")); + } + if (charCount < 0 || byteCount < 0) + { + throw new ArgumentOutOfRangeException(charCount < 0 ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + } + Contract.EndContractBlock(); + + return encoding.GetChars(bytes, byteCount, chars, charCount, decoder: null); + } } } diff --git a/src/mscorlib/src/System/Text/EncodingNLS.cs b/src/mscorlib/src/System/Text/EncodingNLS.cs index d24a10984661..3feb63ed5e04 100644 --- a/src/mscorlib/src/System/Text/EncodingNLS.cs +++ b/src/mscorlib/src/System/Text/EncodingNLS.cs @@ -145,17 +145,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [System.Security.SecurityCritical] // auto-generated public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of diff --git a/src/mscorlib/src/System/Text/UTF32Encoding.cs b/src/mscorlib/src/System/Text/UTF32Encoding.cs index 6ce6702e71be..66d881a5fa97 100644 --- a/src/mscorlib/src/System/Text/UTF32Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF32Encoding.cs @@ -211,17 +211,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [CLSCompliant(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of diff --git a/src/mscorlib/src/System/Text/UTF7Encoding.cs b/src/mscorlib/src/System/Text/UTF7Encoding.cs index aca8a0c8e2fc..fa1111e0e0e1 100644 --- a/src/mscorlib/src/System/Text/UTF7Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF7Encoding.cs @@ -283,17 +283,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [System.Runtime.InteropServices.ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of diff --git a/src/mscorlib/src/System/Text/UTF8Encoding.cs b/src/mscorlib/src/System/Text/UTF8Encoding.cs index d4c6f123d29d..71bc02653f7f 100644 --- a/src/mscorlib/src/System/Text/UTF8Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF8Encoding.cs @@ -241,17 +241,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [System.Runtime.InteropServices.ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of diff --git a/src/mscorlib/src/System/Text/UnicodeEncoding.cs b/src/mscorlib/src/System/Text/UnicodeEncoding.cs index 0d8a9aa09b43..862d9e219729 100644 --- a/src/mscorlib/src/System/Text/UnicodeEncoding.cs +++ b/src/mscorlib/src/System/Text/UnicodeEncoding.cs @@ -213,17 +213,7 @@ public override int GetChars(byte[] bytes, int byteIndex, int byteCount, [System.Runtime.InteropServices.ComVisible(false)] public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { - // Validate Parameters - if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", - Environment.GetResourceString("ArgumentNull_Array")); - - if (charCount < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - Contract.EndContractBlock(); - - return GetChars(bytes, byteCount, chars, charCount, null); + return EncodingForwarder.GetChars(this, bytes, byteCount, chars, charCount); } // Returns a string containing the decoded representation of a range of