Hate to break this to you guys but that's not really how algorithms work.
I'm not saying that there isn't a way to make it faster... the entire galaxy could maybe be indexed somehow into a binary tree to make searching faster... but... actually no that wouldn't work, since the "links" between systems aren't rigid, their based on distance and your ship's range.
The computer doesn't know what systems are in one direction versus another. It does not have that intuition. In order to figure out what systems are in the correct direction, it has to test all the systems which are in range. Or, to put it another way, if you say "only check on the systems that are in the right direction" it might first chest EVERY system to determine if it's in the right direction. You gain nothing.
The galaxy being so massive and procedurally generated, with the jump distances being totally arbitrary (not 'linked' wormholes between systems that could be indexed) makes this a very difficult task, computationally.