Use Pages as List

This commit is contained in:
Ben Adams 2018-08-29 04:42:53 +01:00 committed by Pranav K
parent 7bd9f9cc3e
commit 22a40b6f2b
1 changed files with 6 additions and 6 deletions

View File

@ -11,7 +11,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
{ {
public const int PageSize = 1024; public const int PageSize = 1024;
private int _charIndex; private int _charIndex;
private List<char[]> _pages = new List<char[]>();
public PagedCharBuffer(ICharBufferSource bufferSource) public PagedCharBuffer(ICharBufferSource bufferSource)
{ {
@ -20,14 +19,15 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
public ICharBufferSource BufferSource { get; } public ICharBufferSource BufferSource { get; }
public IList<char[]> Pages => _pages; // Strongly typed rather than IList for performance
public List<char[]> Pages { get; } = new List<char[]>();
public int Length public int Length
{ {
get get
{ {
var length = _charIndex; var length = _charIndex;
var pages = _pages; var pages = Pages;
var fullPages = pages.Count - 1; var fullPages = pages.Count - 1;
for (var i = 0; i < fullPages; i++) for (var i = 0; i < fullPages; i++)
{ {
@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
var pages = _pages; var pages = Pages;
for (var i = pages.Count - 1; i > 0; i--) for (var i = pages.Count - 1; i > 0; i--)
{ {
var page = pages[i]; var page = pages[i];
@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
try try
{ {
page = BufferSource.Rent(PageSize); page = BufferSource.Rent(PageSize);
_pages.Add(page); Pages.Add(page);
} }
catch when (page != null) catch when (page != null)
{ {
@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
public void Dispose() public void Dispose()
{ {
var pages = _pages; var pages = Pages;
var count = pages.Count; var count = pages.Count;
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {