< Summary

Class:DCL.ECS7.ComponentWrapper.Generic.WrappedComponentPool[T]
Assembly:ECS7Plugin.ComponentWrapper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ComponentWrapper/Generic/WrappedComponentPool.cs
Covered lines:15
Uncovered lines:3
Coverable lines:18
Total lines:49
Line coverage:83.3% (15 of 18)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WrappedComponentPool(...)0%110100%
Get()0%220100%
Release(...)0%4.123050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ComponentWrapper/Generic/WrappedComponentPool.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL.ECS7.ComponentWrapper.Generic
 6{
 7    public record WrappedComponentPool<T> where T: class, IWrappedComponent
 8    {
 9        private readonly Func<T> objectFactory;
 10        private readonly List<T> list;
 11
 8512        public WrappedComponentPool(int capacity, Func<T> objectFactory)
 13        {
 8514            list = new List<T>(capacity);
 8515            this.objectFactory = objectFactory;
 8516        }
 17
 18        public PooledWrappedComponent<T> Get()
 19        {
 9620            if (list.Count == 0)
 21            {
 9322                return new PooledWrappedComponent<T>(objectFactory(), this);
 23            }
 24
 325            int index = list.Count - 1;
 326            T wrappedComponent = list[index];
 327            wrappedComponent.ClearFields();
 328            PooledWrappedComponent<T> result = new PooledWrappedComponent<T>(wrappedComponent, this);
 329            list.RemoveAt(index);
 330            return result;
 31        }
 32
 33        public void Release(PooledWrappedComponent<T> element)
 34        {
 2035            for (int i = 0; i < list.Count; i++)
 36            {
 037                if (list[i] == element.WrappedComponent)
 38                {
 39#if UNITY_EDITOR
 040                    Debug.LogError($"element {typeof(T)} already released to the pool");
 41#endif
 042                    return;
 43                }
 44            }
 45
 1046            list.Add(element.WrappedComponent);
 1047        }
 48    }
 49}