forked from bit/DotRecastNetSim
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
|
||||||
- Changed DtPathCorridor.Init(int maxPath) function to allow setting the maximum path [@ikpil](https://github.com/ikpil)
|
- 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)
|
- 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
|
### Removed
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,14 @@ namespace DotRecast.Core.Buffers
|
||||||
{
|
{
|
||||||
public struct Enumerator : IEnumerator<T>
|
public struct Enumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
private readonly RcCyclicBuffer<T> _buffer;
|
private readonly RcCyclicBuffer<T> _cb;
|
||||||
private int _index;
|
private int _index;
|
||||||
private readonly int _size;
|
private readonly int _size;
|
||||||
|
|
||||||
internal Enumerator(RcCyclicBuffer<T> buffer)
|
internal Enumerator(RcCyclicBuffer<T> cb)
|
||||||
{
|
{
|
||||||
_buffer = buffer;
|
_cb = cb;
|
||||||
_size = _buffer._size;
|
_size = _cb._size;
|
||||||
_index = default;
|
_index = default;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace DotRecast.Core.Buffers
|
||||||
_index = -1;
|
_index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Current => _buffer[_index];
|
public T Current => _cb[_index];
|
||||||
|
|
||||||
object IEnumerator.Current => Current;
|
object IEnumerator.Current => Current;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using DotRecast.Core.Buffers;
|
using DotRecast.Core.Buffers;
|
||||||
using DotRecast.Core.Collections;
|
using DotRecast.Core.Collections;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -308,11 +310,12 @@ public class RcCyclicBufferTests
|
||||||
[Test]
|
[Test]
|
||||||
public void RcCyclicBuffer_EnumeratorWorks()
|
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 buffer = new RcCyclicBuffer<int>(5, refValues);
|
||||||
|
|
||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var enumerator = buffer.GetEnumerator();
|
using var enumerator = buffer.GetEnumerator();
|
||||||
enumerator.Reset();
|
enumerator.Reset();
|
||||||
while (enumerator.MoveNext())
|
while (enumerator.MoveNext())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue