all: Run modernize -fix ./...

Closes #14107
This commit is contained in:
Bjørn Erik Pedersen
2025-11-05 20:41:17 +01:00
parent 264022a75a
commit 04650ce778
122 changed files with 275 additions and 351 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ func TestDefaultConfig(t *testing.T) {
func TestDecodeConfigInjectsDefaultAndCompiles(t *testing.T) {
c := qt.New(t)
cfg, err := DecodeConfig(config.BaseConfig{}, map[string]interface{}{})
cfg, err := DecodeConfig(config.BaseConfig{}, map[string]any{})
c.Assert(err, qt.IsNil)
c.Assert(cfg, qt.DeepEquals, DefaultConfig)
-1
View File
@@ -1035,7 +1035,6 @@ func (c *serverCommand) serve() error {
defer cancel()
wg2, ctx := errgroup.WithContext(ctx)
for _, srv := range servers {
srv := srv
wg2.Go(func() error {
return srv.Shutdown(ctx)
})
+8 -11
View File
@@ -38,7 +38,6 @@ func TestXxHashFromReaderPara(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
i := i
wg.Add(1)
go func() {
defer wg.Done()
@@ -75,8 +74,8 @@ func TestXxHashFromStringHexEncoded(t *testing.T) {
func BenchmarkXXHashFromReader(b *testing.B) {
r := strings.NewReader("Hello World")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XXHashFromReader(r)
r.Seek(0, 0)
}
@@ -84,16 +83,16 @@ func BenchmarkXXHashFromReader(b *testing.B) {
func BenchmarkXXHashFromString(b *testing.B) {
s := "Hello World"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XXHashFromString(s)
}
}
func BenchmarkXXHashFromStringHexEncoded(b *testing.B) {
s := "The quick brown fox jumps over the lazy dog"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
XxHashFromStringHexEncoded(s)
}
}
@@ -136,7 +135,7 @@ func BenchmarkHashString(b *testing.B) {
for _, test := range tests {
b.Run(fmt.Sprintf("n%d", len(test)), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
HashString(test)
}
})
@@ -149,9 +148,7 @@ func BenchmarkHashMap(b *testing.B) {
m[fmt.Sprintf("key%d", i)] = i
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
HashString(m)
}
}
+1 -1
View File
@@ -278,7 +278,7 @@ func TestConvertIfPossibleMisc(t *testing.T) {
func BenchmarkToInt64(b *testing.B) {
v := reflect.ValueOf(int(42))
for i := 0; i < b.N; i++ {
for b.Loop() {
ToInt64(v)
}
}
+6 -9
View File
@@ -156,12 +156,12 @@ func BenchmarkIsContextType(b *testing.B) {
b.Run("value", func(b *testing.B) {
ctx := context.Background()
ctxs := make([]reflect.Type, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
ctxs[i] = reflect.TypeOf(context.WithValue(ctx, k("key"), i))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
if !IsContextType(ctxs[i]) {
b.Fatal("not context")
}
@@ -170,7 +170,7 @@ func BenchmarkIsContextType(b *testing.B) {
b.Run("background", func(b *testing.B) {
var ctxt reflect.Type = reflect.TypeOf(context.Background())
for i := 0; i < b.N; i++ {
for b.Loop() {
if !IsContextType(ctxt) {
b.Fatal("not context")
}
@@ -189,8 +189,7 @@ func BenchmarkIsTruthFulValue(b *testing.B) {
nilPointer = reflect.ValueOf((*zeroStruct)(nil))
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
IsTruthfulValue(stringHugo)
IsTruthfulValue(stringEmpty)
IsTruthfulValue(zero)
@@ -227,8 +226,7 @@ func BenchmarkGetMethodByNameForType(b *testing.B) {
tp := reflect.TypeFor[*testStruct]()
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, method := range methods {
_ = GetMethodByNameForType(tp, method)
}
@@ -239,8 +237,7 @@ func BenchmarkGetMethodByName(b *testing.B) {
v := reflect.ValueOf(&testStruct{})
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, method := range methods {
_ = GetMethodByName(v, method)
}
+2 -2
View File
@@ -214,8 +214,8 @@ func TestScratchGetSortedMapValues(t *testing.T) {
func BenchmarkScratchGet(b *testing.B) {
scratch := NewScratch()
scratch.Add("A", 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
scratch.Get("A")
}
}
+7 -7
View File
@@ -75,7 +75,7 @@ func BenchmarkUniqueStrings(b *testing.B) {
input := []string{"a", "b", "d", "e", "d", "h", "a", "i"}
b.Run("Safe", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
result := UniqueStrings(input)
if len(result) != 6 {
b.Fatalf("invalid count: %d", len(result))
@@ -86,13 +86,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
b.Run("Reuse slice", func(b *testing.B) {
b.StopTimer()
inputs := make([][]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := make([]string, len(input))
copy(inputc, input)
inputs[i] = inputc
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := inputs[i]
result := UniqueStringsReuse(inputc)
@@ -105,13 +105,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
b.Run("Reuse slice sorted", func(b *testing.B) {
b.StopTimer()
inputs := make([][]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := make([]string, len(input))
copy(inputc, input)
inputs[i] = inputc
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
inputc := inputs[i]
result := UniqueStringsSorted(inputc)
@@ -123,13 +123,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
}
func BenchmarkGetOrCompileRegexp(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
GetOrCompileRegexp(`\d+`)
}
}
func BenchmarkCompileRegexp(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
regexp.MustCompile(`\d+`)
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ func BenchmarkOnceMoreValue(b *testing.B) {
return counter
}
for range b.N {
for b.Loop() {
omf := OnceMoreValue(f)
for range 10 {
omf.Value(context.Background())
+3 -3
View File
@@ -112,7 +112,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
june06, _ := time.Parse("2006-Jan-02", "2018-Jun-06")
b.Run("Native", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := june06.Format("Monday Jan 2 2006")
if got != "Wednesday Jun 6 2018" {
b.Fatalf("invalid format, got %q", got)
@@ -123,7 +123,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
b.Run("Localized", func(b *testing.B) {
f := NewTimeFormatter(translators.GetTranslator("nn"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
got := f.Format(june06, "Monday Jan 2 2006")
if got != "onsdag juni 6 2018" {
b.Fatalf("invalid format, got %q", got)
@@ -134,7 +134,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
b.Run("Localized Custom", func(b *testing.B) {
f := NewTimeFormatter(translators.GetTranslator("nn"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
got := f.Format(june06, ":date_medium")
if got != "6. juni 2018" {
b.Fatalf("invalid format, got %q", got)
+1 -1
View File
@@ -24,7 +24,7 @@ func TestCacheSize(t *testing.T) {
cache := NewCacheWithOptions[string, string](CacheOptions{Size: 10})
for i := 0; i < 30; i++ {
for i := range 30 {
cache.Set(string(rune('a'+i)), "value")
}
+7 -7
View File
@@ -68,31 +68,31 @@ func BenchmarkOrderedIntSet(b *testing.B) {
}
b.Run("New", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
NewOrderedIntSet(1, 2, 3, 4, 5, 6, 7, 8)
}
})
b.Run("Has small", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
smallSet.Has(i % 32)
}
})
b.Run("Has medium", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
mediumSet.Has(i % 32)
}
})
b.Run("Next", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
mediumSet.Next(i % 32)
}
})
b.Run("ForEachKey small", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
smallSet.ForEachKey(func(key int) bool {
return true
})
@@ -100,7 +100,7 @@ func BenchmarkOrderedIntSet(b *testing.B) {
})
b.Run("ForEachKey medium", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
mediumSet.ForEachKey(func(key int) bool {
return true
})
@@ -108,7 +108,7 @@ func BenchmarkOrderedIntSet(b *testing.B) {
})
b.Run("ForEachKey large", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
largeSet.ForEachKey(func(key int) bool {
return true
})
-1
View File
@@ -52,7 +52,6 @@ func TestPara(t *testing.T) {
var result []int
var mu sync.Mutex
for i := range n {
i := i
r.Run(func() error {
mu.Lock()
defer mu.Unlock()
+2 -2
View File
@@ -115,8 +115,8 @@ func ReplaceExtension(path string, newExt string) string {
func makePathRelative(inPath string, possibleDirectories ...string) (string, error) {
for _, currentPath := range possibleDirectories {
if strings.HasPrefix(inPath, currentPath) {
return strings.TrimPrefix(inPath, currentPath), nil
if after, ok := strings.CutPrefix(inPath, currentPath); ok {
return after, nil
}
}
return inPath, errors.New("can't extract relative path, unknown prefix")
+5 -5
View File
@@ -225,7 +225,7 @@ func BenchmarkSanitize(b *testing.B) {
// This should not allocate any memory.
b.Run("All allowed", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := Sanitize(allAlowedPath)
if got != allAlowedPath {
b.Fatal(got)
@@ -235,7 +235,7 @@ func BenchmarkSanitize(b *testing.B) {
// This will allocate some memory.
b.Run("Spaces", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := Sanitize(spacePath)
if got != "foo-bar" {
b.Fatal(got)
@@ -320,7 +320,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
// This should not allocate any memory.
b.Run("With leading slash", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash(withLeadingSlash)
if got != withLeadingSlash {
b.Fatal(got)
@@ -330,7 +330,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
// This will allocate some memory.
b.Run("Without leading slash", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash(noLeadingSlash)
if got != "/a/b/c" {
b.Fatal(got)
@@ -339,7 +339,7 @@ func BenchmarkAddLeadingSlash(b *testing.B) {
})
b.Run("Blank string", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
got := AddLeadingSlash("")
if got != "/" {
b.Fatal(got)
+2 -2
View File
@@ -637,7 +637,7 @@ func TestHasExt(t *testing.T) {
func BenchmarkParseIdentity(b *testing.B) {
parser := newTestParser()
for i := 0; i < b.N; i++ {
for b.Loop() {
parser.ParseIdentity(files.ComponentFolderAssets, "/a/b.css")
}
}
@@ -656,7 +656,7 @@ func TestSitesMatrixFromPath(t *testing.T) {
func BenchmarkSitesMatrixFromPath(b *testing.B) {
parser := newTestParser()
p := parser.Parse(files.ComponentFolderContent, "/a/b/c.fr.md")
for i := 0; i < b.N; i++ {
for b.Loop() {
parser.SitesMatrixFromPath(p)
}
}
+4 -4
View File
@@ -150,7 +150,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and or no match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2).Or(intP3)
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = p(3).OK()
}
})
@@ -158,7 +158,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and and no match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2)
for range b.N {
for b.Loop() {
_ = p(3).OK()
}
})
@@ -166,7 +166,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("and and match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.And(intP2)
for range b.N {
for b.Loop() {
_ = p(10).OK()
}
})
@@ -174,7 +174,7 @@ func BenchmarkPredicate(b *testing.B) {
b.Run("or or match", func(b *testing.B) {
var p predicate.PR[int] = intP1
p = p.Or(intP2).Or(intP3)
for range b.N {
for b.Loop() {
_ = p(2).OK()
}
})
+1 -1
View File
@@ -65,7 +65,7 @@ func BenchmarkVisitLinesAfter(b *testing.B) {
line 3`
for i := 0; i < b.N; i++ {
for b.Loop() {
VisitLinesAfter(lines, func(s string) {
})
}
+2 -2
View File
@@ -67,12 +67,12 @@ func BenchmarkStringSort(b *testing.B) {
prototype := []string{"b", "Bz", "zz", "ba", "αβδ αβδ αβδ", "A", "Ba", "ba", "nnnnasdfnnn", "AAgæåz", "αβδC"}
b.Run("LessStrings", func(b *testing.B) {
ss := make([][]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
ss[i] = make([]string, len(prototype))
copy(ss[i], prototype)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
sss := ss[i]
sort.Slice(sss, func(i, j int) bool {
return LessStrings(sss[i], sss[j])
+2 -2
View File
@@ -220,8 +220,8 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error {
var hugoEnv []types.KeyValueStr
for _, v := range environ {
key, val := config.SplitEnvVar(v)
if strings.HasPrefix(key, hugoEnvPrefix) {
delimiterAndKey := strings.TrimPrefix(key, hugoEnvPrefix)
if after, ok := strings.CutPrefix(key, hugoEnvPrefix); ok {
delimiterAndKey := after
if len(delimiterAndKey) < 2 {
continue
}
+1 -1
View File
@@ -58,7 +58,7 @@ weight = 4
Filename: configFilename,
}
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := LoadConfig(d)
if err != nil {
b.Fatal(err)
+1 -2
View File
@@ -334,7 +334,6 @@ func TestDefaultConfigProvider(t *testing.T) {
}
for i := range 20 {
i := i
r.Run(func() error {
const v = 42
k := fmt.Sprintf("k%d", i)
@@ -478,7 +477,7 @@ func BenchmarkDefaultConfigProvider(b *testing.B) {
b.Run("Custom", func(b *testing.B) {
cfg := New()
for i := 0; i < b.N; i++ {
for b.Loop() {
runMethods(b, cfg)
}
})
-1
View File
@@ -74,7 +74,6 @@ func TestNewContentFromFile(t *testing.T) {
c := qt.New(t)
for i, cas := range cases {
cas := cas
c.Run(cas.name, func(c *qt.C) {
c.Parallel()
+4 -4
View File
@@ -54,8 +54,8 @@ func TestTrimShortHTML(t *testing.T) {
func BenchmarkTrimShortHTML(b *testing.B) {
c := newTestContentSpec(nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
c.TrimShortHTML([]byte("<p>Simple paragraph</p>"), "markdown")
}
}
@@ -134,8 +134,8 @@ func TestTotalWords(t *testing.T) {
}
func BenchmarkTotalWords(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
wordCount := helpers.TotalWords(totalWordsBenchmarkString)
if wordCount != 400 {
b.Fatal("Wordcount error")
+2 -2
View File
@@ -214,8 +214,8 @@ func TestGetTitleFunc(t *testing.T) {
}
func BenchmarkReaderContains(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for i, this := range containsBenchTestData {
result := helpers.ReaderContains(strings.NewReader(this.v1), this.v2)
if result != this.expect {
+4 -4
View File
@@ -73,8 +73,8 @@ func MakeTitle(inpath string) string {
// MakeTitleInPath converts the path given to a suitable title, trimming whitespace
func MakePathRelative(inPath string, possibleDirectories ...string) (string, error) {
for _, currentPath := range possibleDirectories {
if strings.HasPrefix(inPath, currentPath) {
return strings.TrimPrefix(inPath, currentPath), nil
if after, ok := strings.CutPrefix(inPath, currentPath); ok {
return after, nil
}
}
return inPath, errors.New("can't extract relative path, unknown prefix")
@@ -226,8 +226,8 @@ func ExtractRootPaths(paths []string) []string {
r := make([]string, len(paths))
for i, p := range paths {
root := filepath.ToSlash(p)
sections := strings.Split(root, "/")
for _, section := range sections {
sections := strings.SplitSeq(root, "/")
for section := range sections {
if section != "" {
root = section
break
+4 -4
View File
@@ -259,8 +259,8 @@ func BenchmarkRelURL(b *testing.B) {
v := config.New()
v.Set("baseURL", "https://base/")
p := newTestPathSpecFromCfgAndLang(v, "")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = p.RelURL("https://base/foo/bar", false)
}
}
@@ -271,12 +271,12 @@ func BenchmarkAbsURL(b *testing.B) {
p := newTestPathSpecFromCfgAndLang(v, "")
b.ResetTimer()
b.Run("relurl", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = p.AbsURL("foo/bar", false)
}
})
b.Run("absurl", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = p.AbsURL("https://base/foo/bar", false)
}
})
+1 -3
View File
@@ -59,9 +59,7 @@ func BenchmarkHashingFs(b *testing.B) {
ofs := NewHashingFs(fs, observer)
content := []byte(strings.Repeat("lorem ipsum ", 1000))
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
f, err := ofs.Create(fmt.Sprintf("file%d", i))
if err != nil {
b.Fatal(err)
+2 -2
View File
@@ -81,7 +81,7 @@ func BenchmarkGetGlob(b *testing.B) {
if err != nil {
b.Fatal(err)
}
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = g.Match(search)
}
})
@@ -92,7 +92,7 @@ func BenchmarkGetGlob(b *testing.B) {
runBench("Filenames cache, mixed case searches", defaultGlobCache, "abCDe")
b.Run("GetGlob", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := GetGlob("**/foo")
if err != nil {
b.Fatal(err)
+1 -2
View File
@@ -182,8 +182,7 @@ func BenchmarkWalk(b *testing.B) {
return nil
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
w := NewWalkway(WalkwayConfig{Fs: fs, Root: "root", WalkFn: walkFn})
if err := w.Walk(); err != nil {
+3 -3
View File
@@ -36,12 +36,12 @@ func BenchmarkCascade(b *testing.B) {
c := qt.New(b)
b.StopTimer()
builders := make([]*sitesBuilder, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i] = newCascadeTestBuilder(b, langs)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builder := builders[i]
err := builder.BuildE(BuildCfg{})
c.Assert(err, qt.IsNil)
@@ -83,7 +83,7 @@ kind = '{section,term}'
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
})
-1
View File
@@ -721,7 +721,6 @@ themeconfigdirparam: {{ site.Params.themeconfigdirparam }}
`
for _, configName := range []string{"hugo.toml", "config.toml"} {
configName := configName
t.Run(configName, func(t *testing.T) {
t.Parallel()
-1
View File
@@ -484,7 +484,6 @@ Path: {{ .Path }}|{{.Kind }}
`
for _, format := range []string{"toml", "yaml", "json"} {
format := format
t.Run(format, func(t *testing.T) {
t.Parallel()
-1
View File
@@ -332,7 +332,6 @@ Image: ![alt-"<>&](/destination-"<> 'title-"<>&')
`
for _, enabled := range []bool{true, false} {
enabled := enabled
t.Run(fmt.Sprint(enabled), func(t *testing.T) {
t.Parallel()
b := Test(t, strings.ReplaceAll(files, "ENABLE", fmt.Sprint(enabled)))
+3 -4
View File
@@ -195,7 +195,6 @@ func TestTreePara(t *testing.T) {
)
for i := range 8 {
i := i
r.Run(func() error {
a := &testValue{ID: "/a"}
lock := tree.Lock(true)
@@ -302,7 +301,7 @@ type testValue struct {
func BenchmarkTreeInsert(b *testing.B) {
runBench := func(b *testing.B, numElements int) {
for i := 0; i < b.N; i++ {
for b.Loop() {
tree := doctree.New(
doctree.Config[*testValue]{
Shifter: &testShifter{},
@@ -360,7 +359,7 @@ func BenchmarkWalk(b *testing.B) {
b.Run(fmt.Sprintf("Walk one dimension %d", numElements), func(b *testing.B) {
tree := createTree()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
w := &doctree.NodeShiftTreeWalker[*testValue]{
Tree: tree,
Handle: handle,
@@ -374,7 +373,7 @@ func BenchmarkWalk(b *testing.B) {
b.Run(fmt.Sprintf("Walk all dimensions %d", numElements), func(b *testing.B) {
base := createTree()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for d1 := range 1 {
for d2 := range 2 {
tree := base.Shape(sitesmatrix.Vector{d1, d2, 0})
+2 -2
View File
@@ -32,7 +32,7 @@ func BenchmarkTreeShiftTreeSlice(b *testing.B) {
v := sitesmatrix.Vector{10, 10, 10}
t := doctree.NewTreeShiftTree[string](v)
b.Run("New", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
for l1 := 0; l1 < v[0]; l1++ {
for l2 := 0; l2 < v[1]; l2++ {
for l3 := 0; l3 < v[2]; l3++ {
@@ -43,7 +43,7 @@ func BenchmarkTreeShiftTreeSlice(b *testing.B) {
}
})
b.Run("Shape", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
for l1 := 0; l1 < v[0]; l1++ {
for l2 := 0; l2 < v[1]; l2++ {
for l3 := 0; l3 < v[2]; l3++ {
+2 -2
View File
@@ -183,8 +183,8 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
} else {
contentDir := strings.TrimPrefix(strings.TrimPrefix(meta.Filename, meta.BaseDir), filePathSeparator) + filePathSeparator
if strings.HasPrefix(filename, contentDir) {
relFilename := strings.TrimPrefix(filename, contentDir)
if after, ok := strings.CutPrefix(filename, contentDir); ok {
relFilename := after
absFilename := filepath.Join(meta.Filename, relFilename)
return relFilename, absFilename, nil
}
+2 -2
View File
@@ -674,9 +674,9 @@ func (h *HugoSites) handleDataFile(r *source.File) error {
// Crawl in data tree to insert data
current = h.data
dataPath := r.FileInfo().Meta().PathInfo.Unnormalized().Dir()[1:]
keyParts := strings.Split(dataPath, "/")
keyParts := strings.SplitSeq(dataPath, "/")
for _, key := range keyParts {
for key := range keyParts {
if key != "" {
if _, ok := current[key]; !ok {
current[key] = make(map[string]any)
-2
View File
@@ -346,7 +346,6 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
g, _ := h.workersSite.Start(ctx)
for _, s := range assemblers {
s := s
g.Run(func() error {
return s.assemblePagesStep1()
})
@@ -751,7 +750,6 @@ func (h *HugoSites) postProcess(l logg.LevelLogger) error {
filenames := h.Deps.BuildState.GetFilenamesWithPostPrefix()
for _, filename := range filenames {
filename := filename
g.Run(func() error {
return handleFile(filename)
})
+2 -3
View File
@@ -330,7 +330,7 @@ Single: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {
`
for i := 0; i < 2; i++ {
for range 2 {
b := Test(t, files)
b.AssertFileContent("public/index.html", `List: |/|html: /|rss: /index.xml|$`)
b.AssertFileContent("public/index.xml", `List xml: |/|html: /|rss: /index.xml|$`)
@@ -749,8 +749,7 @@ func BenchmarkBaseline(b *testing.B) {
builders[i] = NewIntegrationTestBuilder(cfg)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
}
+4 -4
View File
@@ -408,8 +408,8 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s
for _, m := range matches {
cm := qt.Commentf("File: %s Expect: %s Got: %s", filename, m, content)
lines := strings.Split(m, "\n")
for _, match := range lines {
lines := strings.SplitSeq(m, "\n")
for match := range lines {
match = strings.TrimSpace(match)
if match == "" || strings.HasPrefix(match, "#") {
continue
@@ -463,8 +463,8 @@ func (s *IntegrationTestBuilder) AssertFs(fs afero.Fs, matches ...string) {
content := strings.TrimSpace((strings.Join(printFsLines, "\n")))
for _, m := range matches {
cm := qt.Commentf("Match: %q\nIn:\n%s", m, content)
lines := strings.Split(m, "\n")
for _, match := range lines {
lines := strings.SplitSeq(m, "\n")
for match := range lines {
match = strings.TrimSpace(match)
var negate bool
if strings.HasPrefix(match, hglob.NegationPrefix) {
-1
View File
@@ -64,7 +64,6 @@ func TestPermalink(t *testing.T) {
}
for i, test := range tests {
i := i
test := test
t.Run(fmt.Sprintf("%s-%d", test.file, i), func(t *testing.T) {
t.Parallel()
-1
View File
@@ -1068,7 +1068,6 @@ func TestPageWithDate(t *testing.T) {
func TestPageWithFrontMatterConfig(t *testing.T) {
for _, dateHandler := range []string{":filename", ":fileModTime"} {
dateHandler := dateHandler
t.Run(fmt.Sprintf("dateHandler=%q", dateHandler), func(t *testing.T) {
t.Parallel()
c := qt.New(t)
+6 -7
View File
@@ -57,12 +57,11 @@ func BenchmarkGetPage(b *testing.B) {
pagePaths := make([]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
pagePaths[i] = fmt.Sprintf("sect%d", r.Intn(10))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
home, _ := s.getPage(nil, "/")
if home == nil {
b.Fatal("Home is nil")
@@ -121,12 +120,12 @@ func BenchmarkGetPageRegular(b *testing.B) {
pagePaths := make([]string, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
pagePaths[i] = path.Join(fmt.Sprintf("/sect%d", r.Intn(10)), fmt.Sprintf("page%d.md", r.Intn(100)))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
page, _ := s.getPage(nil, pagePaths[i])
c.Assert(page, qt.Not(qt.IsNil))
}
@@ -140,13 +139,13 @@ func BenchmarkGetPageRegular(b *testing.B) {
pagePaths := make([]string, b.N)
pages := make([]page.Page, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
pagePaths[i] = fmt.Sprintf("page%d.md", r.Intn(100))
pages[i] = allPages[r.Intn(len(allPages)/3)]
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
page, _ := s.getPage(pages[i], pagePaths[i])
c.Assert(page, qt.Not(qt.IsNil))
}
+1 -1
View File
@@ -187,7 +187,7 @@ func BenchmarkMergeByLanguage(b *testing.B) {
enSite := h.Sites[0]
nnSite := h.Sites[2]
for i := 0; i < b.N; i++ {
for b.Loop() {
merged := nnSite.RegularPages().MergeByLanguage(enSite.RegularPages())
if len(merged) != count {
b.Fatal("Count mismatch")
+2 -2
View File
@@ -77,7 +77,7 @@ func BenchmarkPagesPrevNext(b *testing.B) {
pages = variant.preparePages(pages)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
p := pages[rand.Intn(len(pages))]
variant.run(p, pages)
}
@@ -109,7 +109,7 @@ func BenchmarkPagePageCollections(b *testing.B) {
}
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
p := pages[rand.Intn(len(pages))]
variant.run(p)
}
@@ -26,7 +26,7 @@ func BenchmarkHash(b *testing.B) {
bs := BuildState{}
for i := 0; i < b.N; i++ {
for b.Loop() {
bs.hash(m)
}
}
+2 -3
View File
@@ -102,7 +102,7 @@ My Other Text: {{ $r.Content }}|{{ $r.Permalink }}|
func TestRebuildEditLeafBundleHeaderOnly(t *testing.T) {
t.Parallel()
for i := 0; i < 3; i++ {
for range 3 {
b := TestRunning(t, rebuildFilesSimple)
b.AssertFileContent("public/mysection/mysectionbundle/index.html",
"My Section Bundle Content Content.")
@@ -1797,8 +1797,7 @@ func BenchmarkRebuildContentFileChange(b *testing.B) {
builders[i].Build()
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
bb := builders[i]
bb.EditFileReplaceFunc("content/mysect/p123/index.md", func(s string) string {
return s + "... Edited"
+1 -2
View File
@@ -198,7 +198,7 @@ relPermalink": "/hello.min.a2d1cb24f24b322a7dad520414c523e9.html"
}
func BenchmarkResourceChainPostProcess(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
s := newTestSitesBuilder(b)
for i := range 300 {
@@ -579,7 +579,6 @@ XML: {{ $xml.body }}
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
if !test.shouldRun() {
t.Skip()
+1 -2
View File
@@ -144,8 +144,7 @@ func BenchmarkSegmentsMatch(b *testing.B) {
match := compileSegments(c, fields...)
b.ResetTimer()
for range b.N {
for b.Loop() {
match(SegmentQuery{Site: no, Output: "rss"})
}
}
+2 -2
View File
@@ -85,8 +85,8 @@ func (scp *ShortcodeWithPage) InnerDeindent() template.HTML {
scp.innerDeindentInit.Do(func() {
b := bp.GetBuffer()
text.VisitLinesAfter(string(scp.Inner), func(s string) {
if strings.HasPrefix(s, scp.indentation) {
b.WriteString(strings.TrimPrefix(s, scp.indentation))
if after, ok := strings.CutPrefix(s, scp.indentation); ok {
b.WriteString(after)
} else {
b.WriteString(s)
}
+3 -9
View File
@@ -101,8 +101,6 @@ title: "Shortcodes Galore!"
{"inline", `{{< my.inline >}}Hi{{< /my.inline >}}`, regexpCheck("my.inline;inline:true;closing:true;inner:{Hi};")},
} {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
c := qt.New(t)
@@ -266,7 +264,7 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) {
cnt := 0
in := make([]input, b.N*len(data))
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, this := range data {
replacements := make(map[string]shortcodeRenderer)
for k, v := range this.replacements {
@@ -280,10 +278,9 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) {
}
}
b.ResetTimer()
cnt = 0
ctx := context.Background()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
for j := range data {
currIn := in[cnt]
cnt++
@@ -345,9 +342,7 @@ title: "Markdown Shortcode"
builders[i] = NewIntegrationTestBuilder(cfg)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
}
@@ -644,7 +639,6 @@ String: {{ . | safeHTML }}
func TestInlineShortcodes(t *testing.T) {
for _, enableInlineShortcodes := range []bool{true, false} {
enableInlineShortcodes := enableInlineShortcodes
t.Run(fmt.Sprintf("enableInlineShortcodes=%t", enableInlineShortcodes),
func(t *testing.T) {
t.Parallel()
+1 -1
View File
@@ -363,7 +363,7 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
sitesVersionsRoles := make([][][]*Site, len(sites))
for i := 0; i < len(sites); i++ {
sitesVersionsRoles[i] = make([][]*Site, len(versionsSorted))
for j := 0; j < len(versionsSorted); j++ {
for j := range versionsSorted {
sitesVersionsRoles[i][j] = make([]*Site, len(rolesSorted))
}
}
+2 -2
View File
@@ -504,7 +504,7 @@ func BenchmarkSiteNew(b *testing.B) {
}
b.Run(name, func(b *testing.B) {
sites := make([]*sitesBuilder, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
sites[i] = bm.create(b)
if edit {
sites[i].Running()
@@ -512,7 +512,7 @@ func BenchmarkSiteNew(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
if edit {
b.StopTimer()
}
-1
View File
@@ -30,7 +30,6 @@ import (
func TestSiteWithPageOutputs(t *testing.T) {
for _, outputs := range [][]string{{"html", "json", "calendar"}, {"json"}} {
outputs := outputs
t.Run(fmt.Sprintf("%v", outputs), func(t *testing.T) {
t.Parallel()
doTestSiteWithPageOutputs(t, outputs)
-1
View File
@@ -286,7 +286,6 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
home := s.getPageOldVersion(kinds.KindHome)
for _, test := range tests {
test := test
tt.Run(fmt.Sprintf("sections %s", test.sections), func(c *qt.C) {
c.Parallel()
sections := strings.Split(test.sections, ",")
+3 -3
View File
@@ -49,7 +49,7 @@ func BenchmarkCompare(b *testing.B) {
b.Run("Equal", func(b *testing.B) {
v1 := Vector{1, 2, 3}
v2 := Vector{1, 2, 3}
for range b.N {
for b.Loop() {
v1.Compare(v2)
}
})
@@ -57,7 +57,7 @@ func BenchmarkCompare(b *testing.B) {
b.Run("First different", func(b *testing.B) {
v1 := Vector{1, 2, 3}
v2 := Vector{2, 2, 3}
for range b.N {
for b.Loop() {
v1.Compare(v2)
}
})
@@ -65,7 +65,7 @@ func BenchmarkCompare(b *testing.B) {
b.Run("Last different", func(b *testing.B) {
v1 := Vector{1, 2, 3}
v2 := Vector{1, 2, 4}
for range b.N {
for b.Loop() {
v1.Compare(v2)
}
})
@@ -1125,11 +1125,11 @@ func BenchmarkSitesMatrixContent(b *testing.B) {
for _, multipleDimensions := range []bool{false, true} {
b.Run(fmt.Sprintf("n%d/md%t", numPages, multipleDimensions), func(b *testing.B) {
builders := make([]*hugolib.IntegrationTestBuilder, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i] = newSitesMatrixContentBenchmarkBuilder(b, numPages, true, true)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
})
+16 -16
View File
@@ -339,37 +339,37 @@ func BenchmarkIntSetsComplement(b *testing.B) {
b.ResetTimer()
b.Run("sub set", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets2.Complement(sets1)
}
})
b.Run("super set", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.Complement(sets2)
}
})
b.Run("self", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.Complement(sets1)
}
})
b.Run("self multiple", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.Complement(sets1, sets1, sets1, sets1, sets1, sets1, sets1)
}
})
b.Run("same", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.Complement(sets1Copy)
}
})
b.Run("one overlapping language", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = setsLanguage1.Complement(sets1)
}
})
@@ -399,7 +399,7 @@ func BenchmarkSets(b *testing.B) {
b.ResetTimer()
b.Run("Build", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sitesmatrix.NewIntSetsBuilder(testDims).WithSets(
maps.NewOrderedIntSet(1, 2),
maps.NewOrderedIntSet(1, 2, 3),
@@ -408,32 +408,32 @@ func BenchmarkSets(b *testing.B) {
}
})
b.Run("HasVector", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.HasVector(v1)
_ = sets1.HasVector(v2)
}
})
b.Run("HasAnyVector", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.HasAnyVector(sets2)
}
})
b.Run("FirstVector", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.VectorSample()
}
})
b.Run("LenVectors", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.LenVectors()
}
})
b.Run("ForEachVector", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
allCount := 0
ok := sets1.ForEachVector(func(v sitesmatrix.Vector) bool {
allCount++
@@ -452,7 +452,7 @@ func BenchmarkSets(b *testing.B) {
})
b.Run("EqualsVector pointer equal", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
if !sets1.EqualsVector(sets1) {
b.Fatal("Expected sets1 to equal itself")
}
@@ -460,7 +460,7 @@ func BenchmarkSets(b *testing.B) {
})
b.Run("EqualsVector equal copy", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
if !sets1.EqualsVector(sets1Copy) {
b.Fatal("Expected sets1 to equal its copy")
}
@@ -468,7 +468,7 @@ func BenchmarkSets(b *testing.B) {
})
b.Run("EqualsVector different sets", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
if sets1.EqualsVector(sets2) {
b.Fatal("Expected sets1 to not equal sets2")
}
@@ -476,7 +476,7 @@ func BenchmarkSets(b *testing.B) {
})
b.Run("Distance", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = sets1.VectorSample().Distance(v1)
_ = sets1.VectorSample().Distance(v2)
}
+1 -1
View File
@@ -877,7 +877,7 @@ GetTerms.tags: {{ range .GetTerms "tags" }}{{ .Title }}|{{ end }}
for _, numPages := range []int{100, 1000, 10000, 20000} {
b.Run(fmt.Sprintf("pages_%d", numPages), func(b *testing.B) {
builders := createBuilders(b, numPages)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
})
-1
View File
@@ -186,7 +186,6 @@ func TestTemplateLookupOrder(t *testing.T) {
},
} {
this := this
if this.name != "Variant 1" {
continue
}
+2 -2
View File
@@ -750,8 +750,8 @@ func (s *sitesBuilder) AssertFileContent(filename string, matches ...string) {
s.T.Helper()
content := s.FileContent(filename)
for _, m := range matches {
lines := strings.Split(m, "\n")
for _, match := range lines {
lines := strings.SplitSeq(m, "\n")
for match := range lines {
match = strings.TrimSpace(match)
if match == "" {
continue
+2 -2
View File
@@ -39,7 +39,7 @@ func BenchmarkFinder(b *testing.B) {
f := identity.NewFinder(identity.FinderConfig{})
b.Run("Find one", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
r := f.Contains(b4, m1, -1)
if r == 0 {
b.Fatal("not found")
@@ -48,7 +48,7 @@ func BenchmarkFinder(b *testing.B) {
})
b.Run("Find none", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
r := f.Contains(b5, m1, -1)
if r > 0 {
b.Fatal("found")
+9 -9
View File
@@ -33,7 +33,7 @@ func BenchmarkIdentityManager(b *testing.B) {
}
b.Run("identity.NewManager", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
m := identity.NewManager()
if m == nil {
b.Fatal("manager is nil")
@@ -46,7 +46,7 @@ func BenchmarkIdentityManager(b *testing.B) {
im := identity.NewManager()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
im.AddIdentity(ids[i])
}
@@ -58,7 +58,7 @@ func BenchmarkIdentityManager(b *testing.B) {
im := identity.NewManager()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
im.AddIdentity(id)
}
@@ -67,33 +67,33 @@ func BenchmarkIdentityManager(b *testing.B) {
b.Run("Nop StringIdentity const", func(b *testing.B) {
const id = identity.StringIdentity("test")
for i := 0; i < b.N; i++ {
for b.Loop() {
identity.NopManager.AddIdentity(id)
}
})
b.Run("Nop StringIdentity const other package", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
identity.NopManager.AddIdentity(identitytesting.TestIdentity)
}
})
b.Run("Nop StringIdentity var", func(b *testing.B) {
id := identity.StringIdentity("test")
for i := 0; i < b.N; i++ {
for b.Loop() {
identity.NopManager.AddIdentity(id)
}
})
b.Run("Nop pointer identity", func(b *testing.B) {
id := &testIdentity{base: "a", name: "b"}
for i := 0; i < b.N; i++ {
for b.Loop() {
identity.NopManager.AddIdentity(id)
}
})
b.Run("Nop Anonymous", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
identity.NopManager.AddIdentity(identity.Anonymous)
}
})
@@ -101,7 +101,7 @@ func BenchmarkIdentityManager(b *testing.B) {
func BenchmarkIsNotDependent(b *testing.B) {
runBench := func(b *testing.B, id1, id2 identity.Identity) {
for i := 0; i < b.N; i++ {
for b.Loop() {
isNotDependent(id1, id2)
}
}
+2 -2
View File
@@ -186,8 +186,8 @@ func createBuildPlugins(rs *resources.Spec, assetsResolver *fsResolver, depsMana
isStdin := importer == stdinImporter
var relDir string
if !isStdin {
if strings.HasPrefix(importer, PrefixHugoVirtual) {
relDir = filepath.Dir(strings.TrimPrefix(importer, PrefixHugoVirtual))
if after, ok := strings.CutPrefix(importer, PrefixHugoVirtual); ok {
relDir = filepath.Dir(after)
} else {
rel, found := fs.MakePathRelative(importer, true)
-1
View File
@@ -435,7 +435,6 @@ func newDispatcher[Q, R any](opts Options) (*dispatcherPool[Q, R], error) {
run := func() error {
g, ctx := errgroup.WithContext(ctx)
for _, c := range inOuts {
c := c
g.Go(func() error {
var errBuff bytes.Buffer
ctx := context.WithoutCancel(ctx)
+3 -5
View File
@@ -263,8 +263,7 @@ func BenchmarkExecuteKatex(b *testing.B) {
input := katexInputTemplate
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
message := Message[KatexInput]{
Header: Header{
Version: currentVersion,
@@ -293,7 +292,7 @@ func BenchmarkKatexStartStop(b *testing.B) {
}
runBench := func(b *testing.B, opts Options) {
for i := 0; i < b.N; i++ {
for b.Loop() {
d, err := Start[KatexInput, KatexOutput](opts)
if err != nil {
b.Fatal(err)
@@ -389,8 +388,7 @@ func BenchmarkExecuteGreet(b *testing.B) {
Name: "Person",
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
message := Message[person]{
Header: Header{
Version: currentVersion,
+1 -1
View File
@@ -507,7 +507,7 @@ func BenchmarkI18nTranslate(b *testing.B) {
b.Run(test.name, func(b *testing.B) {
tp := prepareTranslationProvider(b, test, v)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
f := tp.t.Func(test.lang)
actual := f(context.Background(), test.id, test.args)
if actual != test.expected {
+1 -1
View File
@@ -57,7 +57,7 @@ func BenchmarkCollator(b *testing.B) {
b.Run("Single", func(b *testing.B) {
coll := &Collator{c: collate.New(language.English, collate.Loose)}
for i := 0; i < b.N; i++ {
for b.Loop() {
doWork(coll)
}
})
+8 -9
View File
@@ -74,7 +74,6 @@ tabspace
}
for i, input := range testlines {
input := input
expect := expectlines[i]
c.Run(input, func(c *qt.C) {
b := []byte(input)
@@ -100,8 +99,8 @@ func TestSanitizeAnchorNameBlackfriday(t *testing.T) {
func BenchmarkSanitizeAnchorName(b *testing.B) {
input := []byte("God is good: 神真美好")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeGitHub)
if len(result) != 24 {
b.Fatalf("got %d", len(result))
@@ -111,8 +110,8 @@ func BenchmarkSanitizeAnchorName(b *testing.B) {
func BenchmarkSanitizeAnchorNameAsciiOnly(b *testing.B) {
input := []byte("God is good: 神真美好")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeGitHubAscii)
if len(result) != 12 {
b.Fatalf("got %d", len(result))
@@ -122,8 +121,8 @@ func BenchmarkSanitizeAnchorNameAsciiOnly(b *testing.B) {
func BenchmarkSanitizeAnchorNameBlackfriday(b *testing.B) {
input := []byte("God is good: 神真美好")
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
result := sanitizeAnchorName(input, goldmark_config.AutoIDTypeBlackfriday)
if len(result) != 24 {
b.Fatalf("got %d", len(result))
@@ -133,8 +132,8 @@ func BenchmarkSanitizeAnchorNameBlackfriday(b *testing.B) {
func BenchmarkSanitizeAnchorNameString(b *testing.B) {
input := "God is good: 神真美好"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
result := sanitizeAnchorNameString(input, goldmark_config.AutoIDTypeGitHub)
if len(result) != 24 {
b.Fatalf("got %d", len(result))
@@ -339,7 +339,6 @@ Common
}{
{"issue-9819", "asdf\n: {#myid}"},
} {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
b := hugolib.NewIntegrationTestBuilder(
+2 -4
View File
@@ -284,9 +284,7 @@ D.
builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
}
@@ -345,7 +343,7 @@ FENCE
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
}
+2 -2
View File
@@ -77,8 +77,8 @@ func (n *HugoContext) Dump(source []byte, level int) {
}
func (n *HugoContext) parseAttrs(attrBytes []byte) {
keyPairs := bytes.Split(attrBytes, []byte(" "))
for _, keyPair := range keyPairs {
keyPairs := bytes.SplitSeq(attrBytes, []byte(" "))
for keyPair := range keyPairs {
kv := bytes.Split(keyPair, []byte("="))
if len(kv) != 2 {
continue
@@ -28,7 +28,7 @@ func TestWrap(t *testing.T) {
}
func BenchmarkWrap(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
Wrap([]byte("test"), 42)
}
}
+3 -3
View File
@@ -197,7 +197,7 @@ func parseHighlightOptions(in string) (map[string]any, error) {
return opts, nil
}
for _, v := range strings.Split(in, ",") {
for v := range strings.SplitSeq(in, ",") {
keyVal := strings.Split(v, "=")
key := strings.Trim(keyVal[0], " ")
if len(keyVal) != 2 {
@@ -265,8 +265,8 @@ func hlLinesToRanges(startLine int, s string) ([][2]int, error) {
// 1-2 3
// 1 3-4
// 1 3-4
fields := strings.Split(s, " ")
for _, field := range fields {
fields := strings.SplitSeq(s, " ")
for field := range fields {
field = strings.TrimSpace(field)
if field == "" {
continue
+1 -1
View File
@@ -37,7 +37,7 @@ func ExternallyRenderContent(
// Most external helpers exit w/ non-zero exit code only if severe, i.e.
// halting errors occurred. -> log stderr output regardless of state of err
for _, item := range strings.Split(cmderr.String(), "\n") {
for item := range strings.SplitSeq(cmderr.String(), "\n") {
item := strings.TrimSpace(item)
if item != "" {
if err == nil {
@@ -204,12 +204,12 @@ func BenchmarkToc(b *testing.B) {
b.Run("Build", func(b *testing.B) {
var builders []Builder
for i := 0; i < b.N; i++ {
for b.Loop() {
builders = append(builders, newTestTocBuilder())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
b := builders[i]
b.Build()
}
@@ -218,7 +218,7 @@ func BenchmarkToc(b *testing.B) {
b.Run("ToHTML", func(b *testing.B) {
tocs := newTocs(b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
toc := tocs[i]
toc.ToHTML(1, -1, false)
}
+1 -1
View File
@@ -194,7 +194,7 @@ func TestToJSON(t *testing.T) {
func BenchmarkTypeOps(b *testing.B) {
mt := Builtin.MPEGType
mts := DefaultTypes
for i := 0; i < b.N; i++ {
for b.Loop() {
ff := mt.FirstSuffix
_ = ff.FullSuffix
_ = mt.IsZero()
+1 -2
View File
@@ -62,8 +62,7 @@ func BenchmarkHowSimilar(b *testing.B) {
s1 := "Hugo is cool and " + strings.Repeat("fun ", 10) + "!"
s2 := "Hugo is cool and " + strings.Repeat("cool ", 10) + "!"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
howSimilar(s1, s2)
}
}
+2 -4
View File
@@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"
"time"
@@ -148,11 +149,8 @@ func filterDuplicateMounts(mounts []Mount) []Mount {
var x []Mount
for _, m1 := range mounts {
var found bool
for _, m2 := range x {
if m1.Equal(m2) {
if slices.ContainsFunc(x, m1.Equal) {
found = true
break
}
}
if !found {
x = append(x, m1)
+3 -3
View File
@@ -216,7 +216,7 @@ c: "d"
`)
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := d.UnmarshalToMap(data, YAML)
if err != nil {
b.Fatal(err)
@@ -256,7 +256,7 @@ params:
for _, tt := range yamlTests {
b.Run(tt.Title+" no validation", func(b *testing.B) {
for range b.N {
for b.Loop() {
var v any
if err := unmarshalYamlNoValidation(tt.Content, &v); err != nil {
b.Fatal(err)
@@ -265,7 +265,7 @@ params:
})
b.Run(tt.Title+" with validation", func(b *testing.B) {
for range b.N {
for b.Loop() {
var v any
err := UnmarshalYaml(tt.Content, &v)
if tt.IsExpectedToFailValidation {
@@ -280,8 +280,8 @@ func BenchmarkShortcodeLexer(b *testing.B) {
testInputs[i] = []byte(input.input)
}
var cfg Config
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
for _, input := range testInputs {
_, err := collectWithConfig(input, true, lexMainSection, cfg)
if err != nil {
+3 -4
View File
@@ -40,8 +40,7 @@ This is some summary. This is some summary. This is some summary. This is some s
input := []byte(start + strings.Repeat(strings.Repeat("this is text", 30)+"{{< myshortcode >}}This is some inner content.{{< /myshortcode >}}", 10))
cfg := Config{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
if _, err := parseBytes(input, cfg, lexIntroSection); err != nil {
b.Fatal(err)
}
@@ -90,13 +89,13 @@ func BenchmarkHasShortcode(b *testing.B) {
withShortcode := strings.Repeat("this is text", 30) + "{{< myshortcode >}}This is some inner content.{{< /myshortcode >}}" + strings.Repeat("this is text", 30)
withoutShortcode := strings.Repeat("this is text", 30) + "This is some inner content." + strings.Repeat("this is text", 30)
b.Run("Match", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
HasShortcode(withShortcode)
}
})
b.Run("NoMatch", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
HasShortcode(withoutShortcode)
}
})
+2 -2
View File
@@ -244,7 +244,7 @@ func BenchmarkElementsCollectorWriter(b *testing.B) {
</body>
</html>
`
for i := 0; i < b.N; i++ {
for b.Loop() {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector(
config.BuildStats{Enable: true},
))
@@ -272,7 +272,7 @@ func BenchmarkElementsCollectorWriterPre(b *testing.B) {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector(
config.BuildStats{Enable: true},
))
for i := 0; i < b.N; i++ {
for b.Loop() {
fmt.Fprint(w, benchHTML)
}
}
+3 -4
View File
@@ -344,7 +344,7 @@ func BenchmarkRelatedNewIndex(b *testing.B) {
}
b.Run("singles", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
idx := NewInvertedIndex(cfg)
for _, doc := range pages {
idx.Add(context.Background(), doc)
@@ -353,7 +353,7 @@ func BenchmarkRelatedNewIndex(b *testing.B) {
})
b.Run("all", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
idx := NewInvertedIndex(cfg)
docs := make([]Document, len(pages))
for i := range pages {
@@ -401,9 +401,8 @@ func BenchmarkRelatedMatchesIn(b *testing.B) {
idx.Add(context.Background(), newTestDoc(index, allKeywords[start:end]...))
}
b.ResetTimer()
ctx := context.Background()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
if i%10 == 0 {
idx.search(ctx, q2)
} else {
+1 -3
View File
@@ -181,9 +181,7 @@ keywords: ['k%d']
builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
builders[i].Build()
}
}
+5 -5
View File
@@ -469,7 +469,7 @@ func BenchmarkImageExif(b *testing.B) {
getImages := func(c *qt.C, b *testing.B, fs afero.Fs) []images.ImageResource {
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
imgs := make([]images.ImageResource, b.N)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
imgs[i] = fetchResourceForSpec(spec, c, "sunset.jpg", strconv.Itoa(i)).(images.ImageResource)
}
return imgs
@@ -487,7 +487,7 @@ func BenchmarkImageExif(b *testing.B) {
images := getImages(c, b, afero.NewMemMapFs())
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
getAndCheckExif(c, images[i])
}
})
@@ -498,7 +498,7 @@ func BenchmarkImageExif(b *testing.B) {
images := getImages(c, b, afero.NewMemMapFs())
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
for range 10 {
getAndCheckExif(c, images[i])
}
@@ -510,14 +510,14 @@ func BenchmarkImageExif(b *testing.B) {
c := qt.New(b)
fs := afero.NewMemMapFs()
images := getImages(c, b, fs)
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
getAndCheckExif(c, images[i])
}
images = getImages(c, b, fs)
b.StartTimer()
for i := 0; i < b.N; i++ {
for i := 0; b.Loop(); i++ {
getAndCheckExif(c, images[i])
}
})
-2
View File
@@ -43,7 +43,6 @@ func TestHexStringToColor(t *testing.T) {
{"777", color.RGBA{R: 0x77, G: 0x77, B: 0x77, A: 0xff}},
} {
test := test
c.Run(test.arg, func(c *qt.C) {
c.Parallel()
@@ -78,7 +77,6 @@ func TestColorToHexString(t *testing.T) {
{color.RGBA{R: 0x42, G: 0x87, B: 0xf5, A: 0x80}, "#4287f580"},
} {
test := test
c.Run(test.expect, func(c *qt.C) {
c.Parallel()
+1 -2
View File
@@ -99,8 +99,7 @@ func BenchmarkDecodeExif(b *testing.B) {
d, err := NewDecoder()
c.Assert(err, qt.IsNil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err = d.Decode("", imagemeta.JPEG, f)
c.Assert(err, qt.IsNil)
f.Seek(0, 0)
+2 -2
View File
@@ -96,10 +96,10 @@ func (f textFilter) Draw(dst draw.Image, src image.Image, options *gift.Options)
// Calculate lines, consider and include linebreaks
finalLines := []string{}
f.text = strings.ReplaceAll(f.text, "\r", "")
for _, line := range strings.Split(f.text, "\n") {
for line := range strings.SplitSeq(f.text, "\n") {
currentLine := ""
// Break each line at the maximum width.
for _, str := range strings.Fields(line) {
for str := range strings.FieldsSeq(line) {
fieldStrWidth := font.MeasureString(face, str)
currentLineStrWidth := font.MeasureString(face, currentLine)
+6 -6
View File
@@ -172,10 +172,10 @@ func TestIsProbablyHTMLToken(t *testing.T) {
}
func BenchmarkSummaryFromHTML(b *testing.B) {
b.StopTimer()
input := "<p>First paragraph</p><p>Second paragraph</p>"
b.StartTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
summary := ExtractSummaryFromHTML(media.Builtin.MarkdownType, input, 2, false)
if s := summary.Content(); s != input {
b.Fatalf("unexpected content: %q", s)
@@ -190,10 +190,10 @@ func BenchmarkSummaryFromHTML(b *testing.B) {
}
func BenchmarkSummaryFromHTMLWithDivider(b *testing.B) {
b.StopTimer()
input := "<p>First paragraph</p><p>FOOO</p><p>Second paragraph</p>"
b.StartTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
summary := ExtractSummaryFromHTMLWithDivider(media.Builtin.MarkdownType, input, "FOOO")
if s := summary.Content(); s != "<p>First paragraph</p><p>Second paragraph</p>" {
b.Fatalf("unexpected content: %q", s)
+2 -2
View File
@@ -36,7 +36,7 @@ func BenchmarkPagePathsBuilderPath(b *testing.B) {
defer putPagePathBuilder(pb)
pb.Add("foo", "bar")
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = pb.Path(0)
}
}
@@ -48,7 +48,7 @@ func BenchmarkPagePathsBuilderPathDir(b *testing.B) {
pb.Add("foo", "bar")
pb.prefixPath = "foo/"
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = pb.PathDir()
}
}
+1 -2
View File
@@ -80,8 +80,7 @@ func BenchmarkPageCache(b *testing.B) {
}
key := "key"
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
cache.getP(key, nil, pages)
}
}
+1 -1
View File
@@ -99,7 +99,7 @@ func BenchmarkSearchPage(b *testing.B) {
pages = variant.preparePages(pages)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
j := rand.Intn(numPages)
k := variant.search(pages[j], pages)
if k != j {
+1 -2
View File
@@ -236,8 +236,7 @@ func TestPageSortByParamNumeric(t *testing.T) {
func BenchmarkSortByWeightAndReverse(b *testing.B) {
p := createSortTestPages(300)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
p = p.ByWeight().Reverse()
}
}
+1 -2
View File
@@ -313,8 +313,7 @@ func BenchmarkPermalinkExpand(b *testing.B) {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
s, err := expander.Expand("posts", page)
if err != nil {
b.Fatal(err)
+1 -2
View File
@@ -43,8 +43,7 @@ func BenchmarkHashImage(b *testing.B) {
}
defer f.Close()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, err := hashImage(f)
if err != nil {
b.Fatal(err)
@@ -158,7 +158,7 @@ LOCAL_STYLE
logger := loggers.NewDefault()
for i := 0; i < b.N; i++ {
for b.Loop() {
b.StopTimer()
imp := newImportResolver(
strings.NewReader(mainStyles),
-1
View File
@@ -56,7 +56,6 @@ func TestIgnoreDotFilesAndDirectories(t *testing.T) {
}
for i, test := range tests {
test := test
c.Run(fmt.Sprintf("[%d] %s", i, test.path), func(c *qt.C) {
c.Parallel()
v := config.New()
+1 -2
View File
@@ -195,7 +195,6 @@ func TestDictionary(t *testing.T) {
{[]any{5, "b"}, false},
{[]any{"a", "b", "c"}, false},
} {
i := i
test := test
c.Run(fmt.Sprint(i), func(c *qt.C) {
c.Parallel()
@@ -812,7 +811,7 @@ func BenchmarkD2(b *testing.B) {
runBenchmark := func(seed, n, max int) {
name := fmt.Sprintf("n=%d,max=%d", n, max)
b.Run(name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
ns.D(seed, n, max)
}
})
+1 -2
View File
@@ -137,7 +137,6 @@ func TestMerge(t *testing.T) {
{"all nil", []any{nil, nil}, nil, true},
} {
test := test
i := i
t.Run(test.name, func(t *testing.T) {
@@ -162,7 +161,7 @@ func TestMerge(t *testing.T) {
func BenchmarkMerge(b *testing.B) {
ns := newNs()
for i := 0; i < b.N; i++ {
for b.Loop() {
ns.Merge(
map[string]any{"a": 42, "c": 3, "e": 11},
map[string]any{"a": 1, "b": 2},

Some files were not shown because too many files have changed in this diff Show More