mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Revert "perf: faster NetworkWriter pooling (#1616)"
This reverts commit 5128b122fe
.
This commit is contained in:
parent
96e690ef9c
commit
e96b687563
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
// a NetworkWriter that will recycle itself when disposed
|
||||
public class PooledNetworkWriter : NetworkWriter, IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
@ -9,36 +11,27 @@ public void Dispose()
|
||||
NetworkWriterPool.Recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkWriterPool
|
||||
{
|
||||
public const int MaxPoolSize = 10;
|
||||
|
||||
static readonly PooledNetworkWriter[] pool = new PooledNetworkWriter[MaxPoolSize];
|
||||
static int next = -1;
|
||||
static readonly Stack<PooledNetworkWriter> pool = new Stack<PooledNetworkWriter>();
|
||||
|
||||
public static PooledNetworkWriter GetWriter()
|
||||
{
|
||||
if (next == -1)
|
||||
if (pool.Count != 0)
|
||||
{
|
||||
return new PooledNetworkWriter();
|
||||
PooledNetworkWriter writer = pool.Pop();
|
||||
// reset cached writer length and position
|
||||
writer.SetLength(0);
|
||||
return writer;
|
||||
}
|
||||
|
||||
PooledNetworkWriter writer = pool[next];
|
||||
pool[next] = null;
|
||||
next--;
|
||||
|
||||
// reset cached writer length and position
|
||||
writer.SetLength(0);
|
||||
return writer;
|
||||
return new PooledNetworkWriter();
|
||||
}
|
||||
|
||||
public static void Recycle(PooledNetworkWriter writer)
|
||||
{
|
||||
if ((next + 1) < MaxPoolSize)
|
||||
{
|
||||
next++;
|
||||
pool[next] = writer;
|
||||
}
|
||||
pool.Push(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user