Skip to content

Commit

Permalink
Perf tweaks to getBestHops
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Mar 3, 2015
1 parent d0d958f commit 786a7c7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def getBestHops(self, routes, restrictTo=None):
if stn not in avoidPlaces and \
stn.system not in avoidPlaces
)
def _get_destinations(srcStation):
def station_iterator(srcStation):
srcSys = srcStation.system
srcDist = srcSys.distanceTo
for stn in restrictStations:
Expand All @@ -793,8 +793,9 @@ def _get_destinations(srcStation):
srcDist(stnSys)
)
else:
def _get_destinations(srcStation):
yield from tdb.getDestinations(
getDestinations = tdb.getDestinations
def station_iterator(srcStation):
yield from getDestinations(
srcStation,
maxJumps=maxJumpsPer,
maxLyPer=maxLyPer,
Expand All @@ -803,22 +804,21 @@ def _get_destinations(srcStation):
maxLsFromStar=maxLsFromStar,
)

station_iterator = _get_destinations

prog = pbar.Progress(len(routes), 25)
getSelling = self.stationsSelling.get
for route in routes:
if tdenv.progress:
prog.increment(1)
tdenv.DEBUG1("Route = {}", route.str())

srcStation = route.lastStation
srcTradingWith = srcStation.tradingWith
if srcStation.tradingWith is None:
if srcTradingWith is None:
srcTradingWith = srcStation.tradingWith = dict()
startCr = credits + int(route.gainCr * safetyMargin)
routeJumps = len(route.jumps)

srcSelling = self.stationsSelling.get(srcStation.ID, None)
srcSelling = getSelling(srcStation.ID, None)
if not srcSelling:
tdenv.DEBUG1("Nothing sold - next.")
continue
Expand Down

0 comments on commit 786a7c7

Please sign in to comment.