internal/gcimporter: fix performance regression for unified IR
internal/gcimporter: fix performance regression for unified IR

flattenImports used to traverse the transitive closure of all imports by
recursively visiting all imported packages. This is a lot of redundant
work, because flattening happens for every package, the recursion is not
necessary and this change removes the recursion.

Change-Id: Id5a1b3b15ef3ce8e0fc6c945b5484b3dd06bd6b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450755
Run-TryBot: Matthew Dempsky <e56ac2c500064424afac424d4b5e53bd0570a731@google.com>
gopls-CI: kokoro <2ac7b1f3fa578934c95181d4272be0d3bca00121@google.com>
Reviewed-by: Florian Zenker <a58e4cd185f9e97e84542886f10f93df7e06ca3a@google.com>
Reviewed-by: Matthew Dempsky <e56ac2c500064424afac424d4b5e53bd0570a731@google.com>
TryBot-Result: Gopher Robot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>

golang/tools,golang/tools,golang/tools,golang/tools,golang/tools