Introduce UnsafeIL for IL2CPP compatibility.
This commit is contained in:
@@ -18,20 +18,16 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace System.Text.Formatting {
|
||||
/// <summary>
|
||||
/// Specifies an interface for types that act as a set of formatting arguments.
|
||||
/// </summary>
|
||||
public interface IArgSet {
|
||||
/// <summary>
|
||||
/// Specifies an interface for types that act as a set of formatting arguments.
|
||||
/// </summary>
|
||||
public interface IArgSet {
|
||||
/// <summary>
|
||||
/// The number of arguments in the set.
|
||||
/// </summary>
|
||||
@@ -547,37 +543,37 @@ namespace System.Text.Formatting {
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void AppendGeneric<T>(T value, StringView format) {
|
||||
// this looks gross, but T is known at JIT-time so this call tree
|
||||
// gets compiled down to a direct call with no branching
|
||||
if (typeof(T) == typeof(sbyte))
|
||||
Append(__refvalue(__makeref(value), sbyte), format);
|
||||
else if (typeof(T) == typeof(byte))
|
||||
Append(__refvalue(__makeref(value), byte), format);
|
||||
else if (typeof(T) == typeof(short))
|
||||
Append(__refvalue(__makeref(value), short), format);
|
||||
else if (typeof(T) == typeof(ushort))
|
||||
Append(__refvalue(__makeref(value), ushort), format);
|
||||
else if (typeof(T) == typeof(int))
|
||||
Append(__refvalue(__makeref(value), int), format);
|
||||
else if (typeof(T) == typeof(uint))
|
||||
Append(__refvalue(__makeref(value), uint), format);
|
||||
else if (typeof(T) == typeof(long))
|
||||
Append(__refvalue(__makeref(value), long), format);
|
||||
else if (typeof(T) == typeof(ulong))
|
||||
Append(__refvalue(__makeref(value), ulong), format);
|
||||
else if (typeof(T) == typeof(float))
|
||||
Append(__refvalue(__makeref(value), float), format);
|
||||
else if (typeof(T) == typeof(double))
|
||||
Append(__refvalue(__makeref(value), double), format);
|
||||
else if (typeof(T) == typeof(decimal))
|
||||
Append(__refvalue(__makeref(value), decimal), format);
|
||||
else if (typeof(T) == typeof(bool))
|
||||
Append(__refvalue(__makeref(value), bool));
|
||||
else if (typeof(T) == typeof(char))
|
||||
Append(__refvalue(__makeref(value), char), format);
|
||||
else if (typeof(T) == typeof(string))
|
||||
Append((string)(object)value);
|
||||
else {
|
||||
// this looks gross, but T is known at JIT-time so this call tree
|
||||
// gets compiled down to a direct call with no branching
|
||||
if (typeof(T) == typeof(sbyte))
|
||||
Append(*(sbyte*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(byte))
|
||||
Append(*(byte*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(short))
|
||||
Append(*(short*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(ushort))
|
||||
Append(*(ushort*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(int))
|
||||
Append(*(int*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(uint))
|
||||
Append(*(uint*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(long))
|
||||
Append(*(long*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(ulong))
|
||||
Append(*(ulong*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(float))
|
||||
Append(*(float*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(double))
|
||||
Append(*(double*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(decimal))
|
||||
Append(*(decimal*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(bool))
|
||||
Append(*(bool*)Unsafe.AsPointer(ref value));
|
||||
else if (typeof(T) == typeof(char))
|
||||
Append(*(char*)Unsafe.AsPointer(ref value), format);
|
||||
else if (typeof(T) == typeof(string))
|
||||
Append(Unsafe.As<string>(value));
|
||||
else {
|
||||
// first, check to see if it's a value type implementing IStringFormattable
|
||||
var formatter = ValueHelper<T>.Formatter;
|
||||
if (formatter != null)
|
||||
|
Reference in New Issue
Block a user