Browse Source

Optimize: LuaValue.TryRead

AnnulusGames 1 year ago
parent
commit
6124d1400f
1 changed files with 10 additions and 10 deletions
  1. 10 10
      src/Lua/LuaValue.cs

+ 10 - 10
src/Lua/LuaValue.cs

@@ -75,8 +75,8 @@ public readonly struct LuaValue : IEquatable<LuaValue>
             case LuaValueType.String:
             case LuaValueType.String:
                 if (t == typeof(string))
                 if (t == typeof(string))
                 {
                 {
-                    var v = (string)referenceValue!;
-                    result = Unsafe.As<string, T>(ref v);
+                    var v = referenceValue!;
+                    result = Unsafe.As<object, T>(ref v);
                     return true;
                     return true;
                 }
                 }
                 else if (t == typeof(double))
                 else if (t == typeof(double))
@@ -137,8 +137,8 @@ public readonly struct LuaValue : IEquatable<LuaValue>
             case LuaValueType.Function:
             case LuaValueType.Function:
                 if (t == typeof(LuaFunction) || t.IsSubclassOf(typeof(LuaFunction)))
                 if (t == typeof(LuaFunction) || t.IsSubclassOf(typeof(LuaFunction)))
                 {
                 {
-                    var v = (LuaFunction)referenceValue!;
-                    result = Unsafe.As<LuaFunction, T>(ref v);
+                    var v = referenceValue!;
+                    result = Unsafe.As<object, T>(ref v);
                     return true;
                     return true;
                 }
                 }
                 else if (t == typeof(object))
                 else if (t == typeof(object))
@@ -153,8 +153,8 @@ public readonly struct LuaValue : IEquatable<LuaValue>
             case LuaValueType.Thread:
             case LuaValueType.Thread:
                 if (t == typeof(LuaThread))
                 if (t == typeof(LuaThread))
                 {
                 {
-                    var v = (LuaThread)referenceValue!;
-                    result = Unsafe.As<LuaThread, T>(ref v);
+                    var v = referenceValue!;
+                    result = Unsafe.As<object, T>(ref v);
                     return true;
                     return true;
                 }
                 }
                 else if (t == typeof(object))
                 else if (t == typeof(object))
@@ -169,8 +169,8 @@ public readonly struct LuaValue : IEquatable<LuaValue>
             case LuaValueType.UserData:
             case LuaValueType.UserData:
                 if (t == typeof(LuaUserData) || t.IsSubclassOf(typeof(LuaUserData)))
                 if (t == typeof(LuaUserData) || t.IsSubclassOf(typeof(LuaUserData)))
                 {
                 {
-                    var v = (LuaUserData)referenceValue!;
-                    result = Unsafe.As<LuaUserData, T>(ref v);
+                    var v = referenceValue!;
+                    result = Unsafe.As<object, T>(ref v);
                     return true;
                     return true;
                 }
                 }
                 else if (t == typeof(object))
                 else if (t == typeof(object))
@@ -185,8 +185,8 @@ public readonly struct LuaValue : IEquatable<LuaValue>
             case LuaValueType.Table:
             case LuaValueType.Table:
                 if (t == typeof(LuaTable))
                 if (t == typeof(LuaTable))
                 {
                 {
-                    var v = (LuaTable)referenceValue!;
-                    result = Unsafe.As<LuaTable, T>(ref v);
+                    var v = referenceValue!;
+                    result = Unsafe.As<object, T>(ref v);
                     return true;
                     return true;
                 }
                 }
                 else if (t == typeof(object))
                 else if (t == typeof(object))