forked from mirror/DotRecast
RcCyclicBuffer<T> optimizations @wrenge
This commit is contained in:
parent
097a365528
commit
c908daa8c3
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotRecast.Core.Buffers;
|
||||
using DotRecast.Core.Collections;
|
||||
using NUnit.Framework;
|
||||
|
@ -291,7 +293,7 @@ public class RcCyclicBufferTests
|
|||
Assert.That(buffer[i], Is.EqualTo(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void RcCyclicBuffer_RegularForEachWorks()
|
||||
{
|
||||
|
@ -304,21 +306,22 @@ public class RcCyclicBufferTests
|
|||
Assert.That(element, Is.EqualTo(refValues[index++]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[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())
|
||||
{
|
||||
Assert.That(enumerator.Current, Is.EqualTo(refValues[index++]));
|
||||
}
|
||||
|
||||
|
||||
// Ensure Reset works properly
|
||||
index = 0;
|
||||
enumerator.Reset();
|
||||
|
|
Loading…
Reference in New Issue