fix: Eliminates List allocations in various places. (#2158)
This commit is contained in:
parent
6f64cddd0b
commit
4836bff5eb
23 changed files with 263 additions and 200 deletions
|
|
@ -1235,24 +1235,24 @@ namespace Server.Multis
|
|||
return list;
|
||||
}
|
||||
|
||||
public List<Mobile> GetMobiles()
|
||||
public PooledRefList<Mobile> GetMobilesPooled()
|
||||
{
|
||||
if (Map == null || Map == Map.Internal)
|
||||
{
|
||||
return new List<Mobile>();
|
||||
return PooledRefList<Mobile>.Create(0);
|
||||
}
|
||||
|
||||
var list = new List<Mobile>();
|
||||
|
||||
foreach (var mobile in Region.GetMobiles())
|
||||
var mobileList = Region.GetMobilesPooled();
|
||||
for (var i = mobileList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (IsInside(mobile))
|
||||
var mobile = mobileList[i];
|
||||
if (!IsInside(mobile))
|
||||
{
|
||||
list.Add(mobile);
|
||||
mobileList.Remove(mobile);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return mobileList;
|
||||
}
|
||||
|
||||
public virtual bool CheckAosLockdowns(int need) => GetAosCurLockdowns() + need <= GetAosMaxLockdowns();
|
||||
|
|
|
|||
|
|
@ -901,8 +901,10 @@ namespace Server.Multis
|
|||
item.Location = BanLocation;
|
||||
}
|
||||
|
||||
foreach (var mobile in GetMobiles())
|
||||
using var mobiles = GetMobilesPooled();
|
||||
for (var i = 0; i < mobiles.Count; i++)
|
||||
{
|
||||
var mobile = mobiles[i];
|
||||
if (mobile != m)
|
||||
{
|
||||
mobile.Location = BanLocation;
|
||||
|
|
@ -1294,13 +1296,18 @@ namespace Server.Multis
|
|||
// Eject all from house
|
||||
from.RevealingAction();
|
||||
|
||||
foreach (var item in GetItems())
|
||||
var items = GetItems();
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
var item = items[i];
|
||||
item.Location = BanLocation;
|
||||
}
|
||||
|
||||
foreach (var mobile in GetMobiles())
|
||||
using var mobiles = GetMobilesPooled();
|
||||
var list = GetMobilesPooled();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var mobile = list[i];
|
||||
mobile.Location = BanLocation;
|
||||
}
|
||||
|
||||
|
|
@ -1760,13 +1767,17 @@ namespace Server.Multis
|
|||
// Eject all from house
|
||||
from.RevealingAction();
|
||||
|
||||
foreach (var item in context.Foundation.GetItems())
|
||||
var list = context.Foundation.GetItems();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
item.Location = context.Foundation.BanLocation;
|
||||
}
|
||||
|
||||
foreach (var mobile in context.Foundation.GetMobiles())
|
||||
using var mobiles = context.Foundation.GetMobilesPooled();
|
||||
for (var i = 0; i < mobiles.Count; i++)
|
||||
{
|
||||
var mobile = mobiles[i];
|
||||
mobile.Location = context.Foundation.BanLocation;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue