gyp: fix O(n^2) in dependency calculations.
gyp: fix O(n^2) in dependency calculations.

With 1000 targets an O(n^2) in the dependency management starts to be
noticed. This patch takes a 0.2s function to 0.02s. The function is not
parallelized so this is a true 1% speedup.

Also commented on another *potential* performance problem with very
specific dependency graphs.

BUG=362075
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/234813003/
Patch from Daniel Bratell <bratell@opera.com>!

witwall/gyp,witwall/gyp,witwall/gyp,witwall/gyp,witwall/gyp