|
@@ -31,7 +31,7 @@ public sealed class LuaTable
|
|
|
if (index > 0 && index <= array.Length)
|
|
if (index > 0 && index <= array.Length)
|
|
|
{
|
|
{
|
|
|
// Arrays in Lua are 1-origin...
|
|
// Arrays in Lua are 1-origin...
|
|
|
- return MemoryMarshalEx.UnsafeElementAt(array, index - 1);
|
|
|
|
|
|
|
+ return array[index - 1];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -41,18 +41,23 @@ public sealed class LuaTable
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
set
|
|
set
|
|
|
{
|
|
{
|
|
|
- if (key.Type is LuaValueType.Number && double.IsNaN(key.UnsafeRead<double>()))
|
|
|
|
|
|
|
+ if (key.TryReadNumber(out var d))
|
|
|
{
|
|
{
|
|
|
- ThrowIndexIsNaN();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (double.IsNaN(d))
|
|
|
|
|
+ {
|
|
|
|
|
+ ThrowIndexIsNaN();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (TryGetInteger(key, out var index))
|
|
|
|
|
- {
|
|
|
|
|
- if (0 < index && index <= Math.Max(array.Length * 2, 8))
|
|
|
|
|
|
|
+ if (MathEx.IsInteger(d))
|
|
|
{
|
|
{
|
|
|
- EnsureArrayCapacity(index);
|
|
|
|
|
- MemoryMarshalEx.UnsafeElementAt(array, index - 1) = value;
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ var index = (int)d;
|
|
|
|
|
+ if (0 < index && index <= Math.Max(array.Length * 2, 8))
|
|
|
|
|
+ {
|
|
|
|
|
+ if (array.Length < index)
|
|
|
|
|
+ EnsureArrayCapacity(index);
|
|
|
|
|
+ array[index - 1] = value;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -73,6 +78,7 @@ public sealed class LuaTable
|
|
|
{
|
|
{
|
|
|
if (array[i].Type is LuaValueType.Nil) return i;
|
|
if (array[i].Type is LuaValueType.Nil) return i;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return array.Length;
|
|
return array.Length;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -83,6 +89,7 @@ public sealed class LuaTable
|
|
|
set => metatable = value;
|
|
set => metatable = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
public bool TryGetValue(LuaValue key, out LuaValue value)
|
|
public bool TryGetValue(LuaValue key, out LuaValue value)
|
|
|
{
|
|
{
|
|
|
if (key.Type is LuaValueType.Nil)
|
|
if (key.Type is LuaValueType.Nil)
|
|
@@ -95,7 +102,7 @@ public sealed class LuaTable
|
|
|
{
|
|
{
|
|
|
if (index > 0 && index <= array.Length)
|
|
if (index > 0 && index <= array.Length)
|
|
|
{
|
|
{
|
|
|
- value = MemoryMarshalEx.UnsafeElementAt(array, index - 1);
|
|
|
|
|
|
|
+ value = array[index - 1];
|
|
|
return value.Type is not LuaValueType.Nil;
|
|
return value.Type is not LuaValueType.Nil;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -113,7 +120,7 @@ public sealed class LuaTable
|
|
|
if (TryGetInteger(key, out var index))
|
|
if (TryGetInteger(key, out var index))
|
|
|
{
|
|
{
|
|
|
return index > 0 && index <= array.Length &&
|
|
return index > 0 && index <= array.Length &&
|
|
|
- MemoryMarshalEx.UnsafeElementAt(array, index - 1).Type != LuaValueType.Nil;
|
|
|
|
|
|
|
+ array[index - 1].Type != LuaValueType.Nil;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return dictionary.TryGetValue(key, out var value) && value.Type is not LuaValueType.Nil;
|
|
return dictionary.TryGetValue(key, out var value) && value.Type is not LuaValueType.Nil;
|
|
@@ -121,20 +128,15 @@ public sealed class LuaTable
|
|
|
|
|
|
|
|
public LuaValue RemoveAt(int index)
|
|
public LuaValue RemoveAt(int index)
|
|
|
{
|
|
{
|
|
|
- if (index <= 0 || index > array.Length)
|
|
|
|
|
- {
|
|
|
|
|
- throw new IndexOutOfRangeException();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
var arrayIndex = index - 1;
|
|
var arrayIndex = index - 1;
|
|
|
- var value = MemoryMarshalEx.UnsafeElementAt(array, arrayIndex);
|
|
|
|
|
|
|
+ var value = array[arrayIndex];
|
|
|
|
|
|
|
|
if (arrayIndex < array.Length - 1)
|
|
if (arrayIndex < array.Length - 1)
|
|
|
{
|
|
{
|
|
|
array.AsSpan(arrayIndex + 1).CopyTo(array.AsSpan(arrayIndex));
|
|
array.AsSpan(arrayIndex + 1).CopyTo(array.AsSpan(arrayIndex));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- MemoryMarshalEx.UnsafeElementAt(array, array.Length - 1) = default;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ array[^1] = default;
|
|
|
|
|
|
|
|
return value;
|
|
return value;
|
|
|
}
|
|
}
|
|
@@ -153,7 +155,7 @@ public sealed class LuaTable
|
|
|
{
|
|
{
|
|
|
array.AsSpan(arrayIndex, array.Length - arrayIndex - 1).CopyTo(array.AsSpan(arrayIndex + 1));
|
|
array.AsSpan(arrayIndex, array.Length - arrayIndex - 1).CopyTo(array.AsSpan(arrayIndex + 1));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
array[arrayIndex] = value;
|
|
array[arrayIndex] = value;
|
|
|
}
|
|
}
|
|
|
|
|
|