1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

Improved performance (very slightly) when batch recycling incoming messages

This commit is contained in:
lidgren
2011-09-25 10:38:57 +00:00
parent 9e3104f5da
commit 36bf73bfbe
5 changed files with 60 additions and 15 deletions

View File

@@ -21,6 +21,8 @@ using System;
using System.Diagnostics;
using System.Collections.Generic;
// @TODO: examine performance characteristics of using SpinLock when using .Net 4.0
namespace Lidgren.Network
{
/// <summary>
@@ -83,6 +85,25 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Adds an item last/tail of the queue
/// </summary>
public void Enqueue(IEnumerable<T> items)
{
lock (m_lock)
{
foreach (var item in items)
{
if (m_size == m_items.Length)
SetCapacity(m_items.Length + 8); // @TODO move this out of loop
int slot = (m_head + m_size) % m_items.Length;
m_items[slot] = item;
m_size++;
}
}
}
/// <summary>
/// Places an item first, at the head of the queue
/// </summary>