|
|
@@ -33,7 +33,7 @@ public sealed class LuaTable
|
|
|
if (index > 0 && index <= array.Length)
|
|
|
{
|
|
|
// Arrays in Lua are 1-origin...
|
|
|
- return array[index - 1];
|
|
|
+ return MemoryMarshalEx.UnsafeElementAt(array, index - 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -52,7 +52,7 @@ public sealed class LuaTable
|
|
|
if (0 < index && index <= Math.Max(array.Length * 2, 8))
|
|
|
{
|
|
|
EnsureArrayCapacity(index);
|
|
|
- array[index - 1] = value;
|
|
|
+ MemoryMarshalEx.UnsafeElementAt(array, index - 1) = value;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -96,7 +96,7 @@ public sealed class LuaTable
|
|
|
{
|
|
|
if (index > 0 && index <= array.Length)
|
|
|
{
|
|
|
- value = array[index - 1];
|
|
|
+ value = MemoryMarshalEx.UnsafeElementAt(array, index - 1);
|
|
|
return value.Type is not LuaValueType.Nil;
|
|
|
}
|
|
|
}
|
|
|
@@ -113,7 +113,8 @@ public sealed class LuaTable
|
|
|
|
|
|
if (TryGetInteger(key, out var index))
|
|
|
{
|
|
|
- return index > 0 && index <= array.Length && array[index - 1].Type != LuaValueType.Nil;
|
|
|
+ return index > 0 && index <= array.Length &&
|
|
|
+ MemoryMarshalEx.UnsafeElementAt(array, index - 1).Type != LuaValueType.Nil;
|
|
|
}
|
|
|
|
|
|
return dictionary.TryGetValue(key, out var value) && value.Type is not LuaValueType.Nil;
|
|
|
@@ -127,13 +128,14 @@ public sealed class LuaTable
|
|
|
}
|
|
|
|
|
|
var arrayIndex = index - 1;
|
|
|
- var value = array[arrayIndex];
|
|
|
+ var value = MemoryMarshalEx.UnsafeElementAt(array, arrayIndex);
|
|
|
|
|
|
if (arrayIndex < array.Length - 1)
|
|
|
{
|
|
|
array.AsSpan(arrayIndex + 1).CopyTo(array.AsSpan(arrayIndex));
|
|
|
}
|
|
|
- array[^1] = default;
|
|
|
+
|
|
|
+ MemoryMarshalEx.UnsafeElementAt(array, array.Length - 1) = default;
|
|
|
|
|
|
return value;
|
|
|
}
|