using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System.Text
{
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty byte arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
if (byteIndex < 0 || byteIndex > bytes.Length)
throw new ArgumentOutOfRangeException("byteIndex", SR.ArgumentOutOfRange_Index);
- // If nothing to encode return 0, avoid fixed problem
+ // If nothing to encode return 0
if (charCount == 0)
return 0;
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty byte arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fixed doesn't like empty char arrays
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}
using System.Runtime.Serialization;
using System.Text;
using System;
+using System.Runtime.InteropServices;
namespace System.Text
{
throw new ArgumentOutOfRangeException(nameof(bytes),
SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid null fixed problem
- if (bytes.Length == 0)
- bytes = new byte[1];
-
// Just call pointer version
- fixed (byte* pBytes = &bytes[0])
+ fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetCharCount(pBytes + index, count, flush);
}
throw new ArgumentOutOfRangeException(nameof(charIndex),
SR.ArgumentOutOfRange_Index);
-
- // Avoid empty input fixed problem
- if (bytes.Length == 0)
- bytes = new byte[1];
-
int charCount = chars.Length - charIndex;
- if (chars.Length == 0)
- chars = new char[1];
// Just call pointer version
- fixed (byte* pBytes = &bytes[0])
- fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
+ fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount,
pChars + charIndex, charCount, flush);
throw new ArgumentOutOfRangeException(nameof(chars),
SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid empty input problem
- if (bytes.Length == 0)
- bytes = new byte[1];
- if (chars.Length == 0)
- chars = new char[1];
-
// Just call the pointer version (public overrides can't do this)
- fixed (byte* pBytes = &bytes[0])
+ fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
{
- fixed (char* pChars = &chars[0])
+ fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
{
Convert(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, flush,
out bytesUsed, out charsUsed, out completed);
using System.Text;
using System;
+using System.Runtime.InteropServices;
namespace System.Text
{
throw new ArgumentOutOfRangeException(nameof(chars),
SR.ArgumentOutOfRange_IndexCountBuffer);
- // Avoid empty input problem
- if (chars.Length == 0)
- chars = new char[1];
-
// Just call the pointer version
int result = -1;
- fixed (char* pChars = &chars[0])
+ fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
{
result = GetByteCount(pChars + index, count, flush);
}
throw new ArgumentOutOfRangeException(nameof(byteIndex),
SR.ArgumentOutOfRange_Index);
- if (chars.Length == 0)
- chars = new char[1];
-
int byteCount = bytes.Length - byteIndex;
- if (bytes.Length == 0)
- bytes = new byte[1];
// Just call pointer version
- fixed (char* pChars = &chars[0])
- fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
+ fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that charCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount,
throw new ArgumentOutOfRangeException(nameof(bytes),
SR.ArgumentOutOfRange_IndexCountBuffer);
-
- // Avoid empty input problem
- if (chars.Length == 0)
- chars = new char[1];
- if (bytes.Length == 0)
- bytes = new byte[1];
-
// Just call the pointer version (can't do this for non-msft encoders)
- fixed (char* pChars = &chars[0])
+ fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
{
- fixed (byte* pBytes = &bytes[0])
+ fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
{
Convert(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, flush,
out charsUsed, out bytesUsed, out completed);
using System;
using System.Collections;
using System.Globalization;
+using System.Runtime.InteropServices;
using System.Threading;
namespace System.Text
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
- return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
+ return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// All of our public Encodings that don't use EncodingNLS must have this (including EncodingNLS)
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fixed doesn't like empty arrays
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}
using System;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.InteropServices;
namespace System.Text
{
int byteCount = bytes.Length - byteIndex;
- // Fix our input array if 0 length because fixed doesn't like 0 length arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fix our input array if 0 length because fixed doesn't like 0 length arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fix our input array if 0 length because fixed doesn't like 0 length arrays
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}
using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System.Text
{
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like empty arrays
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fixed doesn't like empty arrays
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}
using System;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.InteropServices;
namespace System.Text
{
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fixed doesn't like 0 length arrays.
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}
using System;
using System.Globalization;
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System.Text
{
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = s) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = s) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int byteCount = bytes.Length - byteIndex;
- // Fixed doesn't like 0 length arrays.
- if (bytes.Length == 0)
- bytes = new byte[1];
-
- fixed (char* pChars = chars) fixed (byte* pBytes = &bytes[0])
+ fixed (char* pChars = chars) fixed (byte* pBytes = &MemoryMarshal.GetReference((Span<byte>)bytes))
// Remember that byteCount is # to decode, not size of array.
return GetBytes(pChars + charIndex, charCount, pBytes + byteIndex, byteCount, null);
}
// Just call pointer version
int charCount = chars.Length - charIndex;
- // Fixed doesn't like 0 length arrays.
- if (chars.Length == 0)
- chars = new char[1];
-
- fixed (byte* pBytes = bytes) fixed (char* pChars = &chars[0])
+ fixed (byte* pBytes = bytes) fixed (char* pChars = &MemoryMarshal.GetReference((Span<char>)chars))
// Remember that charCount is # to decode, not size of array
return GetChars(pBytes + byteIndex, byteCount, pChars + charIndex, charCount, null);
}