Use slices package from the stdlib when possible (#5360)

* Use slices from the stdlib when possible

* Add some unit tests

* More small tweaks + add benchmark func
This commit is contained in:
its-josh4
2024-10-28 17:26:23 -07:00
committed by GitHub
parent 093de3bce2
commit c6bcdd89be
38 changed files with 200 additions and 110 deletions

View File

@@ -3,6 +3,7 @@ package scene
import (
"context"
"fmt"
"slices"
"strings"
"time"
@@ -290,7 +291,7 @@ func (i *Importer) populatePerformers(ctx context.Context) error {
}
missingPerformers := sliceutil.Filter(names, func(name string) bool {
return !sliceutil.Contains(pluckedNames, name)
return !slices.Contains(pluckedNames, name)
})
if len(missingPerformers) > 0 {
@@ -517,7 +518,7 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []
}
missingTags := sliceutil.Filter(names, func(name string) bool {
return !sliceutil.Contains(pluckedNames, name)
return !slices.Contains(pluckedNames, name)
})
if len(missingTags) > 0 {

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"time"
"github.com/stashapp/stash/pkg/fsutil"
@@ -28,7 +29,7 @@ func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int,
sourceIDs = sliceutil.AppendUniques(nil, sourceIDs)
// ensure destination is not in source list
if sliceutil.Contains(sourceIDs, destinationID) {
if slices.Contains(sourceIDs, destinationID) {
return errors.New("destination scene cannot be in source list")
}