fix: Cleans up FindItems and removes allocations (#1516)

This commit is contained in:
Kamron Batman 2023-09-28 22:20:36 -07:00 • committed by GitHub
parent a4cabe2fa4
commit d77dac9516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 105 additions and 127 deletions

View file

@ -1,3 +1,4 @@
using System;
using ModernUO.Serialization;
using Server.Network;
using Server.Prompts;
@ -74,9 +75,7 @@ public partial class Key : Item
return;
}
var items = cont.FindItemsByType(new[] { typeof(Key), typeof(KeyRing) });
foreach (var item in items)
foreach (var item in cont.EnumerateItems())
{
if (item is Key key)
{
@ -85,10 +84,8 @@ public partial class Key : Item
key.Delete();
}
}
else
else if (item is KeyRing keyRing)
{
var keyRing = (KeyRing)item;
keyRing.RemoveKey(keyValue);
}
}
@ -101,9 +98,7 @@ public partial class Key : Item
return false;
}
var items = cont.FindItemsByType(new[] { typeof(Key), typeof(KeyRing) });
foreach (var item in items)
foreach (var item in cont.EnumerateItems())
{
if (item is Key key)
{
@ -112,10 +107,8 @@ public partial class Key : Item
return true;
}
}
else
else if (item is KeyRing keyRing)
{
var keyRing = (KeyRing)item;
if (keyRing.ContainsKey(keyValue))
{
return true;