RcCyclicBuffer<T> optimizations @wrenge

This commit is contained in:
ikpil 2024-02-20 01:53:50 +09:00
parent 097a365528
commit c908daa8c3
3 changed files with 14 additions and 10 deletions

View File

@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Changed DtPathCorridor.Init(int maxPath) function to allow setting the maximum path [@ikpil](https://github.com/ikpil)
- Changed from List<T> to RcCyclicBuffer in DtCrowdTelemetry execution timing sampling [@wrenge](https://github.com/wrenge)
- RcCyclicBuffer<T> optimizations [@wrenge](https://github.com/wrenge)
### Removed

View File

@ -10,14 +10,14 @@ namespace DotRecast.Core.Buffers
{
public struct Enumerator : IEnumerator<T>
{
private readonly RcCyclicBuffer<T> _buffer;
private readonly RcCyclicBuffer<T> _cb;
private int _index;
private readonly int _size;
internal Enumerator(RcCyclicBuffer<T> buffer)
internal Enumerator(RcCyclicBuffer<T> cb)
{
_buffer = buffer;
_size = _buffer._size;
_cb = cb;
_size = _cb._size;
_index = default;
Reset();
}
@ -32,7 +32,7 @@ namespace DotRecast.Core.Buffers
_index = -1;
}
public T Current => _buffer[_index];
public T Current => _cb[_index];
object IEnumerator.Current => Current;

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DotRecast.Core.Buffers;
using DotRecast.Core.Collections;
using NUnit.Framework;
@ -308,11 +310,12 @@ public class RcCyclicBufferTests
[Test]
public void RcCyclicBuffer_EnumeratorWorks()
{
var refValues = new[] { 4, 3, 2, 1, 0 };
var refValues = new int[] { 4, 3, 2, 1, 0 };
var buffer = new RcCyclicBuffer<int>(5, refValues);
var index = 0;
var enumerator = buffer.GetEnumerator();
using var enumerator = buffer.GetEnumerator();
enumerator.Reset();
while (enumerator.MoveNext())
{