You've already forked lidgren-network-gen3
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user