From 0bc8fd6cf114a7dd75110d2b6d73b8a9879ce2bf Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 13 Sep 2023 14:34:33 +0800 Subject: [PATCH] chore: slice loop replace --- differs/pip_diff.go | 4 +--- util/diff_utils.go | 12 +++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/differs/pip_diff.go b/differs/pip_diff.go index dae84c26..8667f250 100644 --- a/differs/pip_diff.go +++ b/differs/pip_diff.go @@ -57,9 +57,7 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti } if config.Config.Env != nil { paths := getPythonPaths(config.Config.Env) - for _, p := range paths { - pythonPaths = append(pythonPaths, p) - } + pythonPaths = append(pythonPaths, paths...) } pythonVersions, err := getPythonVersion(path) if err != nil { diff --git a/util/diff_utils.go b/util/diff_utils.go index 3788ee35..18497fce 100644 --- a/util/diff_utils.go +++ b/util/diff_utils.go @@ -60,9 +60,7 @@ func GetAdditions(a, b []string) []string { for _, opCode := range group { j1, j2 := opCode.J1, opCode.J2 if opCode.Tag == 'r' || opCode.Tag == 'i' { - for _, line := range b[j1:j2] { - adds = append(adds, line) - } + adds = append(adds, b[j1:j2]...) } } } @@ -78,9 +76,7 @@ func GetDeletions(a, b []string) []string { for _, opCode := range group { i1, i2 := opCode.I1, opCode.I2 if opCode.Tag == 'r' || opCode.Tag == 'd' { - for _, line := range a[i1:i2] { - dels = append(dels, line) - } + dels = append(dels, a[i1:i2]...) } } } @@ -96,9 +92,7 @@ func GetMatches(a, b []string) []string { if i != len(matchindexes)-1 { start := match.A end := match.A + match.Size - for _, line := range a[start:end] { - matches = append(matches, line) - } + matches = append(matches, a[start:end]...) } } return matches