refactor: using slices.Contains to simplify the code (#9918)
### Purpose This is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains) added in the go1.21 standard library, which can make the code more concise and easy to read. ### Testing Describe what testing has been done, and how the reviewer can test the change if new tests are not included. ### Screenshots If this is a GUI change, include screenshots of the change. If not, please feel free to just delete this section. ### Documentation If this is a user visible change (including API and protocol changes), add a link here to the corresponding pull request on https://github.com/syncthing/docs or describe the documentation changes necessary. ## Authorship Your name and email will be added automatically to the AUTHORS file based on the commit metadata. Signed-off-by: dashangcun <907225865@qq.com> Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -9,6 +9,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
"github.com/syncthing/syncthing/lib/rand"
|
"github.com/syncthing/syncthing/lib/rand"
|
||||||
@@ -268,13 +269,7 @@ func (opts OptionsConfiguration) AutoUpgradeEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (opts OptionsConfiguration) FeatureFlag(name string) bool {
|
func (opts OptionsConfiguration) FeatureFlag(name string) bool {
|
||||||
for _, flag := range opts.FeatureFlags {
|
return slices.Contains(opts.FeatureFlags, name)
|
||||||
if flag == name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LowestConnectionLimit is the lower of ConnectionLimitEnough or
|
// LowestConnectionLimit is the lower of ConnectionLimitEnough or
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
)
|
)
|
||||||
@@ -40,12 +42,7 @@ func (p *deviceFolderDownloadState) Has(file string, version protocol.Vector, in
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, existingIndex := range local.blockIndexes {
|
return slices.Contains(local.blockIndexes, index)
|
||||||
if existingIndex == index {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates internal state of what has been downloaded into the temporary
|
// Update updates internal state of what has been downloaded into the temporary
|
||||||
|
|||||||
Reference in New Issue
Block a user