Skip to content

Commit

Permalink
Use EncodingForwarder for GetChars(byte*, int, char*, int)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesqo committed Jul 4, 2016
1 parent 860434d commit ab47c22
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 66 deletions.
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/ASCIIEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/mscorlib/src/System/Text/EncodingForwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/EncodingNLS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/UTF32Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/UTF7Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/UTF8Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions src/mscorlib/src/System/Text/UnicodeEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab47c22

Please sign in to comment.