From 91e55ec46ca8c2c219f96742d90742b52f4e0b4b Mon Sep 17 00:00:00 2001 From: akostin Date: Fri, 13 Apr 2018 18:16:38 +0300 Subject: [PATCH] Small optimization --- bt2qbt.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bt2qbt.go b/bt2qbt.go index 26e52b5..976296c 100644 --- a/bt2qbt.go +++ b/bt2qbt.go @@ -30,13 +30,13 @@ func ASCIIconvert(s string) (newstring string) { return } -func checknotexists(s string, tags []string) bool { +func checknotexists(s string, tags []string) (bool, string) { for _, value := range tags { if value == s { - return false + return false, s } } - return true + return true, s } func decodetorrentfile(path string) (map[string]interface{}, error) { @@ -405,8 +405,8 @@ func main() { if with_tags == true { for _, label := range value.(map[string]interface{})["labels"].([]interface{}) { if len(label.(string)) > 0 { - if checknotexists(ASCIIconvert(label.(string)), newtags) { - newtags = append(newtags, ASCIIconvert(label.(string))) + if ok, tag := checknotexists(ASCIIconvert(label.(string)), newtags); ok { + newtags = append(newtags, tag) } } } @@ -445,8 +445,8 @@ func main() { if cfg.Section("BitTorrent").HasKey("Session\\Tags") { oldtags = cfg.Section("BitTorrent").Key("Session\\Tags").String() for _, tag := range strings.Split(oldtags, ", ") { - if checknotexists(tag, newtags) { - newtags = append(newtags, tag) + if ok, t := checknotexists(tag, newtags); ok { + newtags = append(newtags, t) } } cfg.Section("BitTorrent").Key("Session\\Tags").SetValue(strings.Join(newtags, ", "))