Fixes dictionary uses (#7)
This commit is contained in:
parent
d4a52344f2
commit
916d404c51
161 changed files with 1211 additions and 1722 deletions
|
|
@ -91,12 +91,9 @@ namespace Server.Commands
|
|||
continue;
|
||||
|
||||
Type type = obj.GetType();
|
||||
|
||||
PropertyInfo[] chain = propertyChains[type];
|
||||
|
||||
string failReason = "";
|
||||
|
||||
if (chain == null)
|
||||
if (!propertyChains.TryGetValue(type, out PropertyInfo[] chain))
|
||||
propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object,
|
||||
PropertyAccess.Read, ref failReason);
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,7 @@ namespace Server.Commands
|
|||
TypeInfo info = new TypeInfo(type);
|
||||
m_Types[type] = info;
|
||||
|
||||
m_Namespaces.TryGetValue(nspace, out List<TypeInfo> nspaces);
|
||||
|
||||
if (nspaces == null)
|
||||
if (!m_Namespaces.TryGetValue(nspace, out List<TypeInfo> nspaces))
|
||||
m_Namespaces[nspace] = nspaces = new List<TypeInfo>();
|
||||
|
||||
nspaces.Add(info);
|
||||
|
|
@ -682,9 +680,8 @@ namespace Server.Commands
|
|||
m_Types = new Dictionary<Type, TypeInfo>();
|
||||
m_Namespaces = new Dictionary<string, List<TypeInfo>>();
|
||||
|
||||
List<Assembly> assemblies = new List<Assembly>();
|
||||
List<Assembly> assemblies = new List<Assembly> { Core.Assembly };
|
||||
|
||||
assemblies.Add(Core.Assembly);
|
||||
|
||||
foreach (Assembly asm in ScriptCompiler.Assemblies)
|
||||
assemblies.Add(asm);
|
||||
|
|
@ -1882,9 +1879,7 @@ namespace Server.Commands
|
|||
|
||||
lastIndex = index;
|
||||
|
||||
table.TryGetValue(index, out SpeechEntry entry);
|
||||
|
||||
if (entry == null)
|
||||
if (!table.TryGetValue(index, out SpeechEntry entry))
|
||||
table[index] = entry = new SpeechEntry(index);
|
||||
|
||||
entry.Strings.Add(text);
|
||||
|
|
@ -1925,12 +1920,12 @@ namespace Server.Commands
|
|||
public int Compare(DocCommandEntry a, DocCommandEntry b)
|
||||
{
|
||||
if (a == null && b == null) return 0;
|
||||
|
||||
|
||||
int v = b?.AccessLevel.CompareTo(a?.AccessLevel) ?? 1;
|
||||
|
||||
if (v != 0)
|
||||
return v;
|
||||
|
||||
|
||||
return a?.Name.CompareTo(b?.Name) ?? 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -2290,9 +2285,7 @@ namespace Server.Commands
|
|||
{
|
||||
html.Write(" <a ");
|
||||
|
||||
m_Types.TryGetValue(parms[j].ParameterType, out TypeInfo typeInfo);
|
||||
|
||||
if (typeInfo != null)
|
||||
if (m_Types.TryGetValue(parms[j].ParameterType, out TypeInfo typeInfo))
|
||||
html.Write("href=\"types/{0}\" ", typeInfo.FileName);
|
||||
|
||||
html.Write("title=\"{0}\">{1}</a>", GetTooltipFor(parms[j]), parms[j].Name);
|
||||
|
|
@ -2732,10 +2725,10 @@ namespace Server.Commands
|
|||
|
||||
if (v != 0)
|
||||
return v;
|
||||
|
||||
|
||||
return a?.Name.CompareTo(b?.Name) ?? 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,9 +251,7 @@ namespace Server.Commands.Generic
|
|||
{
|
||||
if (e.Length >= 1)
|
||||
{
|
||||
Commands.TryGetValue(e.GetString(0), out BaseCommand command);
|
||||
|
||||
if (command == null)
|
||||
if (!Commands.TryGetValue(e.GetString(0), out BaseCommand command))
|
||||
{
|
||||
e.Mobile.SendMessage(
|
||||
"That is either an invalid command name or one that does not support this modifier.");
|
||||
|
|
@ -294,4 +292,4 @@ namespace Server.Commands.Generic
|
|||
impl.Register();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,10 +99,7 @@ namespace Server.Commands
|
|||
{
|
||||
Type type = item.GetType();
|
||||
|
||||
if (table.ContainsKey(type))
|
||||
table[type] = 1 + table[type];
|
||||
else
|
||||
table[type] = 1;
|
||||
table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1;
|
||||
}
|
||||
|
||||
List<KeyValuePair<Type, int>> items = table.ToList();
|
||||
|
|
@ -112,10 +109,7 @@ namespace Server.Commands
|
|||
{
|
||||
Type type = m.GetType();
|
||||
|
||||
if (table.ContainsKey(type))
|
||||
table[type] = 1 + table[type];
|
||||
else
|
||||
table[type] = 1;
|
||||
table[type] = (table.TryGetValue(type, out int value) ? value : 0) + 1;
|
||||
}
|
||||
|
||||
List<KeyValuePair<Type, int>> mobiles = table.ToList();
|
||||
|
|
@ -161,10 +155,8 @@ namespace Server.Commands
|
|||
|
||||
do
|
||||
{
|
||||
typeTable.TryGetValue(itemType, out int[] countTable);
|
||||
|
||||
if (countTable == null)
|
||||
countTable = new int[9];
|
||||
if (!typeTable.TryGetValue(itemType, out int[] countTable))
|
||||
typeTable[itemType] = countTable = new int[9];
|
||||
|
||||
if ((flags & ExpandFlag.Name) != 0)
|
||||
++countTable[0];
|
||||
|
|
@ -253,13 +245,13 @@ namespace Server.Commands
|
|||
++totalCount;
|
||||
|
||||
Type type = item.GetType();
|
||||
int[] parms = table[type];
|
||||
|
||||
if (parms == null)
|
||||
table[type] = parms = new[] { 0, 0 };
|
||||
|
||||
parms[0]++;
|
||||
parms[1] += item.Amount;
|
||||
if (table.TryGetValue(type, out int[] parms))
|
||||
{
|
||||
parms[0]++;
|
||||
parms[1] += item.Amount;
|
||||
} else
|
||||
table[type] = new[] { 1, item.Amount };
|
||||
}
|
||||
|
||||
using (StreamWriter op = new StreamWriter("internal.log"))
|
||||
|
|
@ -319,13 +311,9 @@ namespace Server.Commands
|
|||
int length = bin.ReadInt32();
|
||||
Type objType = types[typeID];
|
||||
|
||||
while (objType != typeof(object))
|
||||
while (objType != null && objType != typeof(object))
|
||||
{
|
||||
if (table.ContainsKey(objType))
|
||||
table[objType] = length + table[objType];
|
||||
else
|
||||
table[objType] = length;
|
||||
|
||||
table[objType] = length + (table.TryGetValue(objType, out int value) ? value : 0);
|
||||
objType = objType.BaseType;
|
||||
total += length;
|
||||
}
|
||||
|
|
@ -362,10 +350,7 @@ namespace Server.Commands
|
|||
|
||||
int v = -aCount.CompareTo(bCount);
|
||||
|
||||
if (v != 0)
|
||||
return v;
|
||||
|
||||
return x.Key.FullName.CompareTo(y.Key.FullName);
|
||||
return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -378,10 +363,7 @@ namespace Server.Commands
|
|||
|
||||
int v = -aCount.CompareTo(bCount);
|
||||
|
||||
if (v != 0)
|
||||
return v;
|
||||
|
||||
return x.Key.FullName.CompareTo(y.Key.FullName);
|
||||
return v != 0 ? v : x.Key.FullName.CompareTo(y.Key.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,16 +125,12 @@ namespace Server
|
|||
if (itemMap == null || itemMap == Map.Internal)
|
||||
continue;
|
||||
|
||||
Dictionary<Point2D, DeltaState> table = mapTable[itemMap];
|
||||
|
||||
if (table == null)
|
||||
if (!mapTable.TryGetValue(itemMap, out Dictionary<Point2D, DeltaState> table))
|
||||
mapTable[itemMap] = table = new Dictionary<Point2D, DeltaState>();
|
||||
|
||||
Point2D p = new Point2D(item.X >> 3, item.Y >> 3);
|
||||
|
||||
DeltaState state = table[p];
|
||||
|
||||
if (state == null)
|
||||
if (!table.TryGetValue(p, out DeltaState state))
|
||||
table[p] = state = new DeltaState(p);
|
||||
|
||||
state.m_List.Add(item);
|
||||
|
|
@ -159,16 +155,12 @@ namespace Server
|
|||
if (itemMap == null || itemMap == Map.Internal)
|
||||
continue;
|
||||
|
||||
Dictionary<Point2D, DeltaState> table = mapTable[itemMap];
|
||||
|
||||
if (table == null)
|
||||
if (!mapTable.TryGetValue(itemMap, out Dictionary<Point2D, DeltaState> table))
|
||||
mapTable[itemMap] = table = new Dictionary<Point2D, DeltaState>();
|
||||
|
||||
Point2D p = new Point2D(item.X >> 3, item.Y >> 3);
|
||||
|
||||
DeltaState state = table[p];
|
||||
|
||||
if (state == null)
|
||||
if (!table.TryGetValue(p, out DeltaState state))
|
||||
table[p] = state = new DeltaState(p);
|
||||
|
||||
state.m_List.Add(item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue