| | | 1 | | using System; |
| | | 2 | | using System.Buffers; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Runtime.CompilerServices; |
| | | 5 | | |
| | | 6 | | namespace Hertzole.ScriptableValues.Helpers |
| | | 7 | | { |
| | | 8 | | internal static class ArrayHelpers |
| | | 9 | | { |
| | | 10 | | public static void EnsureCapacity<T>(ref T[] array, int capacity) |
| | 6024 | 11 | | { |
| | 6024 | 12 | | if (array.Length <= capacity) |
| | 222 | 13 | | { |
| | 222 | 14 | | int length = array.Length; |
| | 222 | 15 | | T[] newArray = ArrayPool<T>.Shared.Rent(capacity * 2); |
| | 222 | 16 | | Array.Copy(array, newArray, length); |
| | 222 | 17 | | ArrayPool<T>.Shared.Return(array, RuntimeHelpers.IsReferenceOrContainsReferences<T>()); |
| | 222 | 18 | | array = newArray; |
| | 222 | 19 | | } |
| | 6024 | 20 | | } |
| | | 21 | | |
| | | 22 | | public static bool SequenceEquals<T>(in ReadOnlySpan<T> left, in ReadOnlySpan<T> right) |
| | 36 | 23 | | { |
| | 36 | 24 | | if (left.Length != right.Length) |
| | 6 | 25 | | { |
| | 6 | 26 | | return false; |
| | | 27 | | } |
| | | 28 | | |
| | 30 | 29 | | EqualityComparer<T> comparer = EqualityComparer<T>.Default; |
| | | 30 | | |
| | 4620 | 31 | | for (int i = 0; i < left.Length; i++) |
| | 2286 | 32 | | { |
| | 2286 | 33 | | if (!comparer.Equals(left[i], right[i])) |
| | 6 | 34 | | { |
| | 6 | 35 | | return false; |
| | | 36 | | } |
| | 2280 | 37 | | } |
| | | 38 | | |
| | 24 | 39 | | return true; |
| | 36 | 40 | | } |
| | | 41 | | } |
| | | 42 | | } |