Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Revert "Use EncodingForwarder for GetByteCount(char[], int, int)"
Browse files Browse the repository at this point in the history
This reverts commit ebfc3ce.
  • Loading branch information
tarekgh committed Apr 7, 2017
1 parent c65480b commit aa6a17d
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 66 deletions.
1 change: 0 additions & 1 deletion src/mscorlib/mscorlib.shared.sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,6 @@
<TextSources Include="$(BclSourcesRoot)\System\Text\EncoderFallback.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\EncoderReplacementFallback.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\Encoding.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\EncodingForwarder.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\EncodingInfo.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\EncodingNLS.cs" />
<TextSources Include="$(BclSourcesRoot)\System\Text\EncodingProvider.cs" />
Expand Down
24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/ASCIIEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,29 @@ internal override void SetDefaultFallbacks()
// parent method is safe

[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down
53 changes: 0 additions & 53 deletions src/mscorlib/src/System/Text/EncodingForwarder.cs

This file was deleted.

24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/EncodingNLS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,29 @@ protected EncodingNLS(int codePage) : base(codePage)
// EncodingNLS, UTF7Encoding, UTF8Encoding, UTF32Encoding, ASCIIEncoding, UnicodeEncoding
// parent method is safe
[System.Security.SecuritySafeCritical] // overrides public transparent member
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down
24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/UTF32Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,29 @@ internal override void SetDefaultFallbacks()
// parent method is safe

[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down
24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/UTF7Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,29 @@ public override int GetHashCode()
// parent method is safe

[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down
24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/UTF8Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,29 @@ internal override void SetDefaultFallbacks()
// parent method is safe

[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down
24 changes: 22 additions & 2 deletions src/mscorlib/src/System/Text/UnicodeEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,29 @@ internal override void SetDefaultFallbacks()
// parent method is safe

[System.Security.SecuritySafeCritical] // auto-generated
public override int GetByteCount(char[] chars, int index, int count)
public override unsafe int GetByteCount(char[] chars, int index, int count)
{
return EncodingForwarder.GetByteCount(this, chars, index, count);
// Validate input parameters
if (chars == null)
throw new ArgumentNullException("chars",
Environment.GetResourceString("ArgumentNull_Array"));

if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

if (chars.Length - index < count)
throw new ArgumentOutOfRangeException("chars",
Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
Contract.EndContractBlock();

// If no input, return 0, avoid fixed empty array problem
if (count == 0)
return 0;

// Just call the pointer version
fixed (char* pChars = chars)
return GetByteCount(pChars + index, count, null);
}

// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
Expand Down

0 comments on commit aa6a17d

Please sign in to comment.