···77 "context"
88 "os"
99 "runtime/pprof"
1010+ "slices"
1011 "sync/atomic"
1112 "time"
1213···2021 "code.gitea.io/gitea/modules/process"
2122 "code.gitea.io/gitea/modules/queue"
2223 "code.gitea.io/gitea/modules/setting"
2323- "code.gitea.io/gitea/modules/util"
2424)
25252626var (
···5454 }
55555656 // skip forks from being indexed if unit is not present
5757- if !util.SliceContains(repoTypes, "forks") && repo.IsFork {
5757+ if !slices.Contains(repoTypes, "forks") && repo.IsFork {
5858 return nil
5959 }
60606161 // skip mirrors from being indexed if unit is not present
6262- if !util.SliceContains(repoTypes, "mirrors") && repo.IsMirror {
6262+ if !slices.Contains(repoTypes, "mirrors") && repo.IsMirror {
6363 return nil
6464 }
65656666 // skip templates from being indexed if unit is not present
6767- if !util.SliceContains(repoTypes, "templates") && repo.IsTemplate {
6767+ if !slices.Contains(repoTypes, "templates") && repo.IsTemplate {
6868 return nil
6969 }
70707171 // skip regular repos from being indexed if unit is not present
7272- if !util.SliceContains(repoTypes, "sources") && !repo.IsFork && !repo.IsMirror && !repo.IsTemplate {
7272+ if !slices.Contains(repoTypes, "sources") && !repo.IsFork && !repo.IsMirror && !repo.IsTemplate {
7373 return nil
7474 }
7575
···11// Copyright 2022 The Gitea Authors. All rights reserved.
22// SPDX-License-Identifier: MIT
3344-// Most of the functions in this file can have better implementations with "golang.org/x/exp/slices".
55-// However, "golang.org/x/exp" is experimental and unreliable, we shouldn't use it.
66-// So lets waiting for the "slices" has be promoted to the main repository one day.
77-84package util
951010-import "strings"
1111-1212-// SliceContains returns true if the target exists in the slice.
1313-func SliceContains[T comparable](slice []T, target T) bool {
1414- return SliceContainsFunc(slice, func(t T) bool { return t == target })
1515-}
1616-1717-// SliceContainsFunc returns true if any element in the slice satisfies the targetFunc.
1818-func SliceContainsFunc[T any](slice []T, targetFunc func(T) bool) bool {
1919- for _, v := range slice {
2020- if targetFunc(v) {
2121- return true
2222- }
2323- }
2424- return false
2525-}
66+import (
77+ "slices"
88+ "strings"
99+)
26102711// SliceContainsString sequential searches if string exists in slice.
2812func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
2913 if len(insensitive) != 0 && insensitive[0] {
3014 target = strings.ToLower(target)
3131- return SliceContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
1515+ return slices.ContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
3216 }
33173434- return SliceContains(slice, target)
1818+ return slices.Contains(slice, target)
3519}
36203721// SliceSortedEqual returns true if the two slices will be equal when they get sorted.
···5741 return true
5842}
59436060-// SliceEqual returns true if the two slices are equal.
6161-func SliceEqual[T comparable](s1, s2 []T) bool {
6262- if len(s1) != len(s2) {
6363- return false
6464- }
6565-6666- for i, v := range s1 {
6767- if s2[i] != v {
6868- return false
6969- }
7070- }
7171- return true
7272-}
7373-7444// SliceRemoveAll removes all the target elements from the slice.
7545func SliceRemoveAll[T comparable](slice []T, target T) []T {
7676- return SliceRemoveAllFunc(slice, func(t T) bool { return t == target })
7777-}
7878-7979-// SliceRemoveAllFunc removes all elements which satisfy the targetFunc from the slice.
8080-func SliceRemoveAllFunc[T comparable](slice []T, targetFunc func(T) bool) []T {
8181- idx := 0
8282- for _, v := range slice {
8383- if targetFunc(v) {
8484- continue
8585- }
8686- slice[idx] = v
8787- idx++
8888- }
8989- return slice[:idx]
4646+ return slices.DeleteFunc(slice, func(t T) bool { return t == target })
9047}