From 8287c5c8726ba473d4c1c9b1003bd1632dc8a364 Mon Sep 17 00:00:00 2001 From: Andrew Aldridge Date: Thu, 11 Jul 2013 19:44:49 -0400 Subject: [PATCH] Use static empty pathfinding path when possible --- OpenRA.Mods.RA/Move/PathFinder.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index 92d7e15112..037f312cfb 100755 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -25,6 +25,8 @@ namespace OpenRA.Mods.RA.Move public class PathFinder { + readonly static List emptyPath = new List(0); + readonly World world; public PathFinder(World world) { this.world = world; } @@ -50,7 +52,7 @@ namespace OpenRA.Mods.RA.Move Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick); if (world.FrameNumber - cached.tick > MaxPathAge) CachedPaths.Remove(cached); - return new List(cached.result); + return emptyPath; } var mi = self.Info.Traits.Get(); @@ -61,7 +63,7 @@ namespace OpenRA.Mods.RA.Move { var passable = mi.GetMovementClass(world.TileSet); if (!domainIndex.IsPassable(from, target, (uint)passable)) - return new List(0); + return emptyPath; } var pb = FindBidiPath( @@ -103,7 +105,7 @@ namespace OpenRA.Mods.RA.Move var passable = mi.GetMovementClass(world.TileSet); tilesInRange = new List(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable))); if (tilesInRange.Count() == 0) - return new List(0); + return emptyPath; } var path = FindBidiPath( @@ -144,7 +146,7 @@ namespace OpenRA.Mods.RA.Move } // no path exists - return new List(0); + return emptyPath; } } @@ -209,7 +211,7 @@ namespace OpenRA.Mods.RA.Move return path; } - return new List(0); + return emptyPath; } }