From a1121556be891f215916cf941068d86f9c9830e1 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Wed, 27 Sep 2023 18:36:08 +0800 Subject: [PATCH] refactor: remove redundant `len` check (#2291) `len` returns 0 if the slice or map is nil. From the Go specification [1]: "1. For a nil slice, the number of iterations is 0." "3. If the map is nil, the number of iterations is 0." Therefore, an additional `len(v) != 0` check for before the loop is unnecessary. [1]: https://go.dev/ref/spec#For_range Signed-off-by: Eng Zer Jun --- get.go | 6 ++---- query.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/get.go b/get.go index c1a41730..b2c6b22a 100644 --- a/get.go +++ b/get.go @@ -26,10 +26,8 @@ func printPkgbuilds(dbExecutor download.DBSearcher, aurClient aur.QueryClient, logger.Errorln(err) } - if len(pkgbuilds) != 0 { - for target, pkgbuild := range pkgbuilds { - logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild)) - } + for target, pkgbuild := range pkgbuilds { + logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild)) } if len(pkgbuilds) != len(targets) { diff --git a/query.go b/query.go index 497319b0..ece55a5b 100644 --- a/query.go +++ b/query.go @@ -80,10 +80,8 @@ func syncInfo(ctx context.Context, run *runtime.Runtime, missing = true } - if len(info) != 0 { - for i := range info { - printInfo(run.Logger, run.Cfg, &info[i], cmdArgs.ExistsDouble("i")) - } + for i := range info { + printInfo(run.Logger, run.Cfg, &info[i], cmdArgs.ExistsDouble("i")) } if missing {