Improved efficiency of startup methods.
- ShpReader will copy the input stream into memory just once rather than for every header. - ShpReader.CopyImageData switched to use Array.Copy since that uses some unsafe magic for speed. - In ActorInfo, cache a GetType call and prevent needless materialization in PrerequisitesOf. - In ObjectCreator, cache type and ctor lookups since these are expensive and often repeated. - Implement IReadOnlyDictionary<T, U> on Cache<T, U> to provide some supplementary functions. - In TechTree.GatherOwnedPrerequisites, rearrange a Boolean 'and' expression to evaluate expensive functions later in the chain, and use ContainsKey to speed up name check.
This commit is contained in:
@@ -94,7 +94,11 @@ namespace OpenRA
|
||||
while (t.Count != 0)
|
||||
{
|
||||
var prereqs = PrerequisitesOf(t[index]);
|
||||
var unsatisfied = prereqs.Where(n => !ret.Any(x => x.GetType() == n || n.IsAssignableFrom(x.GetType())));
|
||||
var unsatisfied = prereqs.Where(n => !ret.Any(x =>
|
||||
{
|
||||
var type = x.GetType();
|
||||
return type == n || n.IsAssignableFrom(type);
|
||||
}));
|
||||
if (!unsatisfied.Any())
|
||||
{
|
||||
ret.Add(t[index]);
|
||||
@@ -111,14 +115,13 @@ namespace OpenRA
|
||||
return ret;
|
||||
}
|
||||
|
||||
static List<Type> PrerequisitesOf(ITraitInfo info)
|
||||
static IEnumerable<Type> PrerequisitesOf(ITraitInfo info)
|
||||
{
|
||||
return info
|
||||
.GetType()
|
||||
.GetInterfaces()
|
||||
.Where( t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof( Requires<> ) )
|
||||
.Select( t => t.GetGenericArguments()[ 0 ] )
|
||||
.ToList();
|
||||
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Requires<>))
|
||||
.Select(t => t.GetGenericArguments()[0]);
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<string, Type>> GetInitKeys()
|
||||
|
||||
Reference in New Issue
Block a user