internal/vulncheck: avoid recomputing if module is known

This also makes the code cleaner.

Change-Id: Ia59ed7dbf6487ee1ddcb67ffb05bd57668268e62
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/594217
Reviewed-by: Maceo Thompson <maceothompson@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Zvonimir Pavlinovic 2024-06-24 19:58:01 +00:00
Родитель 03a0c2f3be
Коммит afa91f17c8
1 изменённых файлов: 3 добавлений и 5 удалений

Просмотреть файл

@ -220,12 +220,10 @@ func matchesPlatformComponent(s string, ps []string) bool {
// it figures the module from package importPath. It returns the module
// whose path is the longest prefix of importPath.
func (aff affectingVulns) moduleVulns(module, importPath string) *ModVulns {
unknown := func(module string) bool {
return module == "" || module == internal.UnknownModulePath
}
moduleKnown := module != "" && module != internal.UnknownModulePath
isStd := IsStdPackage(importPath)
var mostSpecificMod *ModVulns // for the case where unknown(module)
var mostSpecificMod *ModVulns // for the case where !moduleKnown
for _, mod := range aff {
md := mod
if isStd && mod.Module.Path == internal.GoStdModulePath {
@ -234,7 +232,7 @@ func (aff affectingVulns) moduleVulns(module, importPath string) *ModVulns {
return md
}
if !unknown(module) {
if moduleKnown {
if mod.Module.Path == module {
// If we know exactly which module we need,
// return its vulnerabilities.