Merge pull request #15785 from crystalstall/main

refactor: using slices.Contains to simplify the code
This commit is contained in:
Julius Volz 2025-01-13 10:31:41 +01:00 committed by GitHub
commit 0d7db907a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 23 deletions

View file

@ -19,6 +19,7 @@ import (
"fmt"
"log/slog"
"net"
"slices"
"strconv"
"strings"
"time"
@ -248,12 +249,7 @@ func (d *Discovery) shouldWatchFromName(name string) bool {
return true
}
for _, sn := range d.watchedServices {
if sn == name {
return true
}
}
return false
return slices.Contains(d.watchedServices, name)
}
// shouldWatchFromTags returns whether the service of the given name should be watched based on its tags.

View file

@ -221,7 +221,7 @@ type BlockMetaCompaction struct {
}
func (bm *BlockMetaCompaction) SetOutOfOrder() {
if bm.containsHint(CompactionHintFromOutOfOrder) {
if bm.FromOutOfOrder() {
return
}
bm.Hints = append(bm.Hints, CompactionHintFromOutOfOrder)
@ -229,16 +229,7 @@ func (bm *BlockMetaCompaction) SetOutOfOrder() {
}
func (bm *BlockMetaCompaction) FromOutOfOrder() bool {
return bm.containsHint(CompactionHintFromOutOfOrder)
}
func (bm *BlockMetaCompaction) containsHint(hint string) bool {
for _, h := range bm.Hints {
if h == hint {
return true
}
}
return false
return slices.Contains(bm.Hints, CompactionHintFromOutOfOrder)
}
const (

View file

@ -15,6 +15,7 @@ package testutil
import (
"net"
"slices"
"sync"
"testing"
)
@ -48,12 +49,7 @@ func RandomUnprivilegedPort(t *testing.T) int {
}
func portWasUsed(port int) bool {
for _, usedPort := range usedPorts {
if port == usedPort {
return true
}
}
return false
return slices.Contains(usedPorts, port)
}
func getPort() (int, error) {