< Summary

Information
Class: Hertzole.ScriptableValues.CollectionExtensions
Assembly: Hertzole.ScriptableValues
File(s): ./Packages/se.hertzole.scriptable-values/Runtime/Extensions/CollectionExtensions.cs
Tag: 52_28197466029
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 76
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TryEnsureCapacity[T](...)0%440100%
ToNativeArray[T](...)0%220100%
ToNativeArray[T](...)0%110100%
ToNativeList[T](...)0%110100%

File(s)

./Packages/se.hertzole.scriptable-values/Runtime/Extensions/CollectionExtensions.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using Unity.Collections;
 3
 4namespace Hertzole.ScriptableValues
 5{
 6    public static class CollectionExtensions
 7    {
 8        internal static bool TryEnsureCapacity<T>(this ICollection<T> list, int capacity)
 789        {
 7810            if (list is List<T> genericList)
 3611            {
 3612                if (genericList.Capacity < capacity)
 2413                {
 2414                    genericList.Capacity = capacity;
 2415                }
 16
 3617                return true;
 18            }
 19
 4220            if (list is ScriptableList<T> scriptableList)
 3621            {
 3622                scriptableList.EnsureCapacity(capacity);
 3623                return true;
 24            }
 25
 626            return false;
 7827        }
 28
 29        /// <summary>
 30        ///     Returns a <see cref="NativeArray{T}" /> that is a copy of this list.
 31        /// </summary>
 32        /// <remarks>This method supports both <c>struct</c> and <c>unmanaged</c> types.</remarks>
 33        /// <typeparam name="T">The type of elements in the list.</typeparam>
 34        /// <param name="list">The list to copy.</param>
 35        /// <param name="allocator">The allocator to use.</param>
 36        /// <returns>An array that is a copy of this list.</returns>
 37        public static NativeArray<T> ToNativeArray<T>(this ScriptableList<T> list, Allocator allocator) where T : struct
 638        {
 639            NativeArray<T> nativeArray = new NativeArray<T>(list.Count, allocator, NativeArrayOptions.UninitializedMemor
 4840            for (int i = 0; i < list.Count; i++)
 1841            {
 1842                nativeArray[i] = list[i];
 1843            }
 44
 645            return nativeArray;
 646        }
 47
 48#if SCRIPTABLE_VALUES_UNITY_COLLECTIONS
 49        /// <summary>
 50        ///     Returns a <see cref="NativeArray{T}" /> that is a copy of this list.
 51        /// </summary>
 52        /// <remarks>This method only supports <c>unmanaged</c> types.</remarks>
 53        /// <typeparam name="T">The type of elements in the list.</typeparam>
 54        /// <param name="list">The list to copy.</param>
 55        /// <param name="allocator">The allocator to use.</param>
 56        /// <returns>An array that is a copy of this list.</returns>
 57        public static NativeArray<T> ToNativeArray<T>(this ScriptableList<T> list, AllocatorManager.AllocatorHandle allo
 658        {
 659            return list.list.ToNativeArray(allocator);
 660        }
 61
 62        /// <summary>
 63        ///     Returns a <see cref="NativeList{T}" /> that is a copy of this list.
 64        /// </summary>
 65        /// <remarks>This method only supports <c>unmanaged</c> types.</remarks>
 66        /// <typeparam name="T">The type of elements in the list.</typeparam>
 67        /// <param name="list">The list to copy.</param>
 68        /// <param name="allocator">The allocator to use.</param>
 69        /// <returns>A <see cref="NativeList{T}" /> that is a copy of this list.</returns>
 70        public static NativeList<T> ToNativeList<T>(this ScriptableList<T> list, AllocatorManager.AllocatorHandle alloca
 671        {
 672            return list.list.ToNativeList(allocator);
 673        }
 74#endif
 75    }
 76}