The faster way to implement this is to ask the TreeWalk if the entry exists in tree #1.  We already know in memory whether or not the file exists, we don't need to stat it again:

  if (tw.getRawMode(1) != 0) {