< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Runtime.Pool<T>
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Runtime/Pool.cs
Line coverage
35%
Covered lines: 6
Uncovered lines: 11
Coverable lines: 17
Total lines: 54
Line coverage: 35.2%
Branch coverage
16%
Covered branches: 1
Total branches: 6
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
Take()50%2240%
Return(...)0%220%
Clear()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Runtime/Pool.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace CoreWCF.Runtime
 5{
 6    internal class Pool<T> where T : class
 7    {
 8        private readonly T[] _items;
 9
 610        public Pool(int maxCount)
 11        {
 612            _items = new T[maxCount];
 613        }
 14
 615        public int Count { get; private set; }
 16
 17        public T Take()
 18        {
 619            if (Count > 0)
 20            {
 021                T item = _items[--Count];
 022                _items[Count] = null;
 023                return item;
 24            }
 25            else
 26            {
 627                return null;
 28            }
 29        }
 30
 31        public bool Return(T item)
 32        {
 033            if (Count < _items.Length)
 34            {
 035                _items[Count++] = item;
 036                return true;
 37            }
 38            else
 39            {
 040                return false;
 41            }
 42        }
 43
 44        public void Clear()
 45        {
 046            for (int i = 0; i < Count; i++)
 47            {
 048                _items[i] = null;
 49            }
 50
 051            Count = 0;
 052        }
 53    }
 54}