]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
all: Run modernize -fix ./...
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 5 Nov 2025 19:41:17 +0000 (20:41 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 5 Nov 2025 20:05:42 +0000 (21:05 +0100)
Closes #14107

122 files changed:
cache/httpcache/httpcache_test.go
commands/server.go
common/hashing/hashing_test.go
common/hreflect/convert_test.go
common/hreflect/helpers_test.go
common/hstore/scratch_test.go
common/hstrings/strings_test.go
common/hsync/oncemore_test.go
common/htime/time_test.go
common/maps/cache_test.go
common/maps/orderedintset_test.go
common/para/para_test.go
common/paths/path.go
common/paths/path_test.go
common/paths/pathparser_test.go
common/predicate/predicate_test.go
common/text/transform_test.go
compare/compare_strings_test.go
config/allconfig/load.go
config/allconfig/load_test.go
config/defaultConfigProvider_test.go
create/content_test.go
helpers/content_test.go
helpers/general_test.go
helpers/path.go
helpers/url_test.go
hugofs/hashing_fs_test.go
hugofs/hglob/glob_test.go
hugofs/walk_test.go
hugolib/cascade_test.go
hugolib/config_test.go
hugolib/content_map_test.go
hugolib/content_render_hooks_test.go
hugolib/doctree/nodeshiftree_test.go
hugolib/doctree/treeshifttree_test.go
hugolib/filesystems/basefs.go
hugolib/hugo_sites.go
hugolib/hugo_sites_build.go
hugolib/hugo_smoke_test.go
hugolib/integrationtest_builder.go
hugolib/page_permalink_test.go
hugolib/page_test.go
hugolib/pagecollections_test.go
hugolib/pages_language_merge_test.go
hugolib/pages_test.go
hugolib/pagesfromdata/pagesfromgotmpl_test.go
hugolib/rebuild_test.go
hugolib/resource_chain_test.go
hugolib/segments/segments_test.go
hugolib/shortcode.go
hugolib/shortcode_test.go
hugolib/site.go
hugolib/site_benchmark_new_test.go
hugolib/site_output_test.go
hugolib/site_sections_test.go
hugolib/sitesmatrix/dimensions_test.go
hugolib/sitesmatrix/sitematrix_integration_test.go
hugolib/sitesmatrix/vectorstores_test.go
hugolib/taxonomy_test.go
hugolib/template_test.go
hugolib/testhelpers_test.go
identity/finder_test.go
identity/identity_test.go
internal/js/esbuild/resolve.go
internal/warpc/warpc.go
internal/warpc/warpc_test.go
langs/i18n/i18n_test.go
langs/language_test.go
markup/goldmark/autoid_test.go
markup/goldmark/codeblocks/codeblocks_integration_test.go
markup/goldmark/goldmark_integration_test.go
markup/goldmark/hugocontext/hugocontext.go
markup/goldmark/hugocontext/hugocontext_test.go
markup/highlight/config.go
markup/internal/external.go
markup/tableofcontents/tableofcontents_test.go
media/mediaType_test.go
metrics/metrics_test.go
modules/collect.go
parser/metadecoders/decoder_test.go
parser/pageparser/pageparser_shortcode_test.go
parser/pageparser/pageparser_test.go
publisher/htmlElementsCollector_test.go
related/inverted_index_test.go
related/related_integration_test.go
resources/image_test.go
resources/images/color_test.go
resources/images/exif/exif_test.go
resources/images/text.go
resources/page/page_markup_test.go
resources/page/page_paths_test.go
resources/page/pages_cache_test.go
resources/page/pages_sort_search_test.go
resources/page/pages_sort_test.go
resources/page/permalinks_test.go
resources/resource_test.go
resources/resource_transformers/cssjs/inline_imports_test.go
source/content_directory_test.go
tpl/collections/collections_test.go
tpl/collections/merge_test.go
tpl/collections/querify_test.go
tpl/collections/sort_test.go
tpl/collections/vitter_test.go
tpl/collections/where_test.go
tpl/hash/hash_test.go
tpl/internal/go_templates/htmltemplate/exec_test.go
tpl/internal/go_templates/testenv/testenv.go
tpl/internal/go_templates/testenv/testenv_test.go
tpl/internal/go_templates/texttemplate/exec_test.go
tpl/internal/go_templates/texttemplate/funcs.go
tpl/internal/go_templates/texttemplate/hugo_template.go
tpl/internal/go_templates/texttemplate/parse/parse.go
tpl/partials/partials_integration_test.go
tpl/strings/strings.go
tpl/strings/truncate_test.go
tpl/time/time_test.go
tpl/tplimpl/templatedescriptor_test.go
tpl/tplimpl/templatestore_integration_test.go
tpl/transform/unmarshal_test.go
transform/livereloadinject/livereloadinject_test.go
transform/urlreplacers/absurlreplacer_test.go
watcher/filenotify/poller_test.go

index 60c07d056131d575789d28eadefb1a15d491eb23..737dff23958899b0d8c1d9be0e81f88eb7a970be 100644 (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)
 
index 82b18c6086e3ec83d965497455f732ef8b94b9d3..db82defc94b1bd283474f84ad0a3bc28841f8c44 100644 (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)
                })
index 105b6d8b59176405adf92f8d43714ab4c131dc2e..8a165786a8e65eee0e576b95bc8353ae806914f3 100644 (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)
        }
 }
index a130c4f1fb36fbba6163f331c3f447262f2d6828..c64526ef61e84287c9df793cd35255d5148b10a4 100644 (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)
        }
 }
index 6a6e7b26b378f576b30c35cb4563690a7801d382..9527fbb7d3d0f72f02ab5027b402aaaac93684f3 100644 (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)
                }
index b7253ab2af253ebd8f85343e8f3d7133714fe139..1f08d46a92ea894bfdb0aea73f5db80a8bea0336 100644 (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")
        }
 }
index 8c485130ece1c70f86c0816246434be27b8edf84..205005785703c086a40982e623ef00962d14ace8 100644 (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+`)
        }
 }
index e0b60418b05238e29a3ca2c56ebacacf44326c73..67a6e04d1df8df7422357998dac25713f85b3f1a 100644 (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())
index 78954887e3a04754534390afaa88c857854d3951..a84d1c3bb4dc371b5f7748e7cd2642c4c3bed38d 100644 (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)
index 17e38ace8ae60a54cb2cbdf7e92cfbf8460e6462..32bff95728c02326232dd8477980f37dbafb92d2 100644 (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")
        }
 
index 243d0d617a4ef1cb51be97ec5f5406b01490e233..2aab63028747dbeabdd9e65c76e69cc6ce2c3c40 100644 (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
                        })
index cf24a4e37593778f48bc4c91ff5f4e46f6c248d4..3d28a017d7b59addff8c2f932afba38af8228572 100644 (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()
index de91d6a2ff27999ac36a766792059bdbdebd8e58..e9b9108f514ecc23652f4f01c7cf8f3bee27e372 100644 (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")
index 0e0dfc2e292e18ca4c822e1e731eab0170480120..ebfd5acd7c5f2f6acfdb6ce6b982e602a0c06867 100644 (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)
index d7286d903704f44a2f99649a2d18909fe3be5dbe..843b286c22455f4d7e96160532eb50dbb143de73 100644 (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)
        }
 }
index 5a9c8365b294e216a76d7fd6fa78e49f2d0e3db5..7cfc11d11745ec810e0bee3c0857063b1f308551 100644 (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()
                }
        })
index 74bb37783e069fac7f44d55047902a2ee4975312..e5ed3567f6620332bcf5507a591d53a4de73147c 100644 (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) {
                })
        }
index 1a5bb0b1a115486013a2e61025856d0f7e468243..505eaa7a3fa46064b3f76c08e86d9726bff045e9 100644 (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])
index 4527a45546fb52e693d1bb9f736578e84fe36615..ec6b71e05ed1f7eff7946d4c0374aa055073c457 100644 (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
                        }
index 3c16e71e9502f735b914d3518e256d94a0c88549..10a88d7b7bf3a47799108a47efbeb9129ddad8f1 100644 (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)
index 204861216a82e758b8a38f7799c6c9372f4a5d41..a21d573ed5ef3182b3e5f14bd076cde1262407f0 100644 (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)
                }
        })
index 22629fdbc6ce0fc7b66751298b41395824d1b366..deafaed0943f180488bbc430512671921a9fa099 100644 (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()
index dd7c5a4c569a7fcde1e9783a0d71c6270457b9be..e2c755a7b18019fc3eca5103691ad1bcc1adddfd 100644 (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")
index f7bcb66425f5840fd0ed77121966d6e70a97f323..53c1925d4676d8c4734bab2e23ade0a53898c613 100644 (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 {
index aee6172823beec4109d76df7b6909e09924b0a00..f8f1e2ecec3a282b4049b90a989cd553c1490d53 100644 (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
index 7f625035c7dad7c6378633eb4328dc2fe8eb7f2b..309dee18af49b4becb6962b9571555cb51d29bdf 100644 (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)
                }
        })
index 74781ba8d76b0458974ff07c33356522876f9e47..0d436a87eadb3121cb888d0706f4cb464f7ffd3b 100644 (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)
index e69e0e6223923310436dcb5eee977791bab99767..72b6752426046d9ae8d0dcf9c7bec8b94c59ac18 100644 (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)
index d8dc0d9b0e7024cd2c5b367e9d3e521e43eba1c7..9d37cb07f9562a6b3ac81859cd185699339ac972 100644 (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 {
index e7a4f7917e05e007c425c9f5375e7566ff3b3a0b..659006a2c73a4267213eabbc9088479e7f141d6f 100644 (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()
                }
        })
index 5ee13ca30e80ae295988ab51e79b2bf575818ad2..c7c09359415198b60097b03e396850860b3d8691 100644 (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()
 
index 971be7b55f68de2d9b2534279b3fa9668373a25b..6882711fec33df93342803482a46da1a51a8089e 100644 (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()
 
index c4e15a5c674298eba83840b848b60d232dece489..31ce545b56236c8a0e437cbd86476dbdf0c29187 100644 (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)))
index 946e6d1872728e9c575285fe19efc7cef4a8d42d..74ce26043e1a6f6b9870ce88721bb9251b273c5a 100644 (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})
index b0ae79633a58f49266d502dce82695aa27722c8a..f5b5802cd05c588e2bae56ca734049d55a7e8ce6 100644 (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++ {
index dd3d97e6c2591347b19b2d1f79f034ca973053f0..9fa561906d343b82d658d04f4415e8383e752a90 100644 (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
                        }
index 5621cd6e6061141cfbcd99e660ddc82699003702..b1ac8fb2555820887e5d8b881bd53a4380b54363 100644 (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)
index 3cd30c41dfb5192152d0b1ec5173869771f8c867..b0157bb597568a31749f3e9178ad3dede585ba3f 100644 (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)
                })
index c6508bc04ff01584f98845097e071286e166b41c..9b4079dc974aa1c41ceb8a581a42deed6dd7f39c 100644 (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()
        }
 }
index 210a53d328a1cb100ff83355994cb88a8705a91d..d1d787797b1275df663b05f00d75dd3443e0400c 100644 (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) {
index d8fd99d79e564044e9d66cac82e3df31d0ec46df..03fe62cecc32e205d773de6d874538422c5a2bf0 100644 (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()
index e8f8ced027f4ccbdf77430242e2a7a619aff2181..b8d56f758cb88244733bb4acbd1a28d67c490290 100644 (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)
index 10c973b7ef85e78094be342fe8a07ac7c8031d08..0ea757b1c2a318a3a24072a434b3c39c1813712c 100644 (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))
                }
index ba1ed83ded4a200676e8b5976388be8ab969effb..62f040739242dc78394c08d7916290e28bc8e389 100644 (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")
index 30e9e59d2d3d2da633045be80f471d28a0a62952..cbcaad48d5fdfb5141009aaa76d4615ac86a13a4 100644 (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)
                                }
index c60b56dbf00fd5d0399e5f0c048081f350956d7a..59cfa7abe4445ec47fdbeb4cf0d836299a71f794 100644 (file)
@@ -26,7 +26,7 @@ func BenchmarkHash(b *testing.B) {
 
        bs := BuildState{}
 
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                bs.hash(m)
        }
 }
index 657ed560980df779710e2258facb21accb8f70d2..53a3bef6ccc49fc16af7a0f5ec36abce922fcf0b 100644 (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"
index 36e50ae3ba6abf51dc67d0b9ed0f3e0ef755a42a..a8bd2d56f8ca435ea100e36cf86b6533573a9f49 100644 (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()
index d98df281c08ded48c60a4c14c279fd1e6bcbd9ce..f07dea969fd4c2bd7da951d935d0a6e4ba8dcb17 100644 (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"})
        }
 }
index 20fe2bc9d09d9895e026589a493f6100df80c673..ec6e25cd675c54de4f8b20472287a87c7ac3649d 100644 (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)
                        }
index 90fda65935fa234a8ee250d0e2f4a38aeecfaa02..cf0a77f18e2f0232b1e8b2a8e45755d316f68b28 100644 (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()
index be75f5c7b8e494f3a9c692d8f459564ff61560a6..ce0331200ed648e1aa44aac16cbe8477d6e40514 100644 (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))
                }
        }
index 023d8e4d5f96c6df170c2261892385c2a7adbd99..75f53cbfdb353fc708dd31f049decfa5e93b9644 100644 (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()
                                        }
index caec4c7007fad0afe73810d16c60eae26f885ac4..14997f688baee9b6574f79704cb343632fbfd2f2 100644 (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)
index 357d3e77d0a710bb6730c2a4247c6e4d0d9d9589..a64c653b06f97d66df496b13640f41977cc76534 100644 (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, ",")
index 6d138a9d4d12861f48e48d8f3f6f7a59e19ee208..83cb5aa4c1ca4ff4999b2e1b71e5b55a62563324 100644 (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)
                }
        })
index 9408a701d82b40ff02d37b4d7cd215fedc63d1d9..3e93e8f96003fcc7ad1c5e1e7b273ff3eac5f651 100644 (file)
@@ -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()
                                }
                        })
index 2f41a3bc9aedacb7101493454d6c39947f13e47c..1365c90556fde5005734a227d7ce9142983a63c1 100644 (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)
                }
index 2727353673c0f9efc609d04732e7667fddd63523..4b30108593edd3e255466e261f1739b68d45a965 100644 (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()
                        }
                })
index 31b18bdc464538b7b1bbf822e1fe2db0c182761a..56b9c3f9bb0ccd85f35dd3ededd4bed1bd6a65b7 100644 (file)
@@ -186,7 +186,6 @@ func TestTemplateLookupOrder(t *testing.T) {
                },
        } {
 
-               this := this
                if this.name != "Variant 1" {
                        continue
                }
index 2007b658dd0f911e7211dd603085ec2cdb17b3d7..2fa3d563444e1cad5bbb45f5feb51eb33a043fe6 100644 (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
index 949a43713a4aaf0f369da1093884d4b2a8eb9565..85a5fd9280b2d7030de5f327fb727412b049cad8 100644 (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")
index dac92d86b43b8f451960a6f7dc63ab2faef8a8cf..a14ab615dd7cc0dda656186e415c256b70dbbc20 100644 (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)
                }
        }
index a2516dbd2cdc7ceeb72f05043ebbf6813572ed92..18ad8a40a9059d5239524e82c536646c1a3bdb22 100644 (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)
 
index e21fefa8a74604ee4d5ba8e2c34fd4e44d9b0517..0d8d6a030dc145f6ec382a3ea4a46ce65ae28874 100644 (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)
index 2ee4c3de59cba9aa4e9791486cf410d2509ec4a6..d19334806319b590f547229947d371ad823beb1a 100644 (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,
index a23cee5393ae7270e185303b58a4b802b3cf5d3a..7d5a7c8b5d8753d2e2e49aa0eaf123f8921dba77 100644 (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 {
index 33240f3f49a977e1f75eee6408987382ba06cbab..e8d319f040bd1a35306c120219d3848618081036 100644 (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)
                }
        })
index e0770d86c7b8f941419a90eb4b1712abaaa61dab..a2a7551d004d6e7fae343793bbe6d29467e4724f 100644 (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))
index 2fd4fa17046566f7cd7638077508b58330fd700a..c4da3d2e4800778308cd7d009b7d77cf66f532f3 100644 (file)
@@ -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(
index a6eac4e483239a0aef41897827087171063ef508..8dc24593f306a7d61929dd03db94a76a79fdd3b3 100644 (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()
                }
        }
index 7a556083c6a34102510cdc521a2b0abcca3f561f..8afe64b7ff869ee7d4316b193381340c8c0217fe 100644 (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
index 62769f4d0c3de4cbfcfe469b5e9e583bb42b6c6a..5971900129721a8e7785c2bd8ac4b833e04cb6dd 100644 (file)
@@ -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)
        }
 }
index b19e9ec1b003e7448f1173820190674fd896c9b1..fff9bfeca8354d21d2e4f953b0e8d2d29bd51da8 100644 (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
index dc8cc61c20ff7c922ae99d5b639eb16e95116dcf..dcb8932ca78564a0ba1922c86de3f684a7634595 100644 (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 {
index b07d9e3aded5edb801974f011436a7ab219bc5f4..d851561503f06aa0a07356cae257657c2496f845 100644 (file)
@@ -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)
                }
index 3b8e099b897255dd6a269ec25dff1d82a3623a44..43504ac793ef5a8cff452c009d0133b7a4b8bfde 100644 (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()
index 6e799a393134cc7601f55e98526d2e62593aa2a7..83dc1433f17ad16f1926b678c910d253101cf9c2 100644 (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)
        }
 }
index bf027b3720719b04764cca1e93839d641f6dd247..9a86c814029caeead323dd9a35c77ae63fd8ced3 100644 (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) {
-                               found = true
-                               break
-                       }
+               if slices.ContainsFunc(x, m1.Equal) {
+                       found = true
                }
                if !found {
                        x = append(x, m1)
index bc5e93d1669e82b007ff61e7ffb26b3098c0102d..678197f7daa37b516dc32ea7df471e5882311cef 100644 (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 {
index 976597af25d251030c3d41ce11bcba5e07b134a9..47c33a86d1ba6948bfa63373d160be2c6ae4f023 100644 (file)
@@ -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 {
index c6bedbd6fd3aad16adc28dd8bbee42793e482d1b..de7d2e140531ea7808805a0ec4a4c46b35c4cde4 100644 (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)
                }
        })
index 36447258eb30544d4eff2e7f730c1ae86cc19d1e..2e6ebdf2112323da4acab7025b6143f06dbeeea1 100644 (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)
        }
 }
index d57237e111ef12e2292f75ab96145c59cb2d4ecb..c44be4a6289fd92926ad60846939a14b06d56bf6 100644 (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 {
index 6d3c6d6de9305ea67c661247329cdb568e118bf7..18ec51f4afa980c34b0d92e2568dbf76387c09bb 100644 (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()
        }
 }
index ee5de8bec21ffe452a9dce6f7694875cde0f1ff9..9b9c69f49ced42fe00b5dd2d591d7fc8a8e8691a 100644 (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])
                }
        })
index 3a75c068e453740e5e0c2c6cd5a7041996f3b8d7..540f3bea8d5eb9d168a2519513aac5f0acb3b7f6 100644 (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()
 
index 278bc761aefa4526c8ca9aea583a64d91a58d1c6..3aab7d8bbb2731bf8d6c223d3e3d1454a725efbb 100644 (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)
index f3943a475b19469c2288714c77cdc5d184f257eb..11c6eac41f6ebd02082d7a85919e96d3ca2dd691 100644 (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)
 
index 43eaae6f6ad450dade1fa9b20091b1d2647ff3ab..fc1102434517a32724bcf8eeb05860cd2c54fbe7 100644 (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)
index e2765ec6553431ebbe8bd7322bb5cbd8ceae1ae8..a396d9143451fbd133d94ee65fa82d2de5373e12 100644 (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()
        }
 }
index 9e6af1c2879b11adf7931c269f7e8e2c1ba4daa1..6cbc71d10c54936d6d25d7715ee2dfd9d4f39832 100644 (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)
        }
 }
index 8f115109c57046f1a48de4d2652cc62a84e57ed0..9c5fdd550e13a02a365cef77469e211a0086ff2d 100644 (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 {
index 70c7bc8a8182a31fc3e142094facef7a5315d8d8..f437f54ed98825681cb71df23e9765c62cbe75bd 100644 (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()
        }
 }
index 90d6784007576b9b5ad96523302fe3d958b9c8e4..9b3c315ed11fdc76e7c8eafb150eafae3130422e 100644 (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)
index d077704564c8afb397fd8f8d5e7753ffc3ac120a..0d1e921de2198ae5e43d99ccf69bf64a9b4b4c8a 100644 (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)
index 9bcb7f9a311292db05e13ad5b094c936df3c94d7..3578e261286dcb3fbafa60432ad092e46241084c 100644 (file)
@@ -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),
index fea83fd52adf7c589afff94bc79a7d3b9adedff9..d4e276fed33fdcf2351cdb9577eb513764a535d2 100644 (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()
index 0face752c06bd561074748307d95c5b220a0a7ad..8099ea91dd1490de08a620587416d353d1861895 100644 (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)
                        }
                })
index a8ef0afeacc1687aa7ab87a1022fe998ecdafe16..f6589b6d48f60b2de1523ae533b04a9fefcf08ab 100644 (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},
index 17556e4cbfb00680f7526fb754bb62effc199b55..9d4f72923f728c123acb0baf64a24c0a6e0ec52d 100644 (file)
@@ -85,8 +85,7 @@ func BenchmarkQuerify(b *testing.B) {
        ns := newNs()
        params := []any{"a", "b", "c", "d", "f", " &"}
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                _, err := ns.Querify(params...)
                if err != nil {
                        b.Fatal(err)
@@ -98,8 +97,7 @@ func BenchmarkQuerifySlice(b *testing.B) {
        ns := newNs()
        params := []string{"a", "b", "c", "d", "f", " &"}
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                _, err := ns.Querify(params)
                if err != nil {
                        b.Fatal(err)
@@ -111,8 +109,7 @@ func BenchmarkQuerifyMap(b *testing.B) {
        ns := newNs()
        params := map[string]any{"a": "b", "c": "d", "f": " &"}
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                _, err := ns.Querify(params)
                if err != nil {
                        b.Fatal(err)
index cc45819213d53acd840ee1a0f69250c3666d20e8..4fc95ac8a9b686b2ae5f8443af9270c54b9430be 100644 (file)
@@ -265,7 +265,7 @@ func TestSort(t *testing.T) {
 func BenchmarkSortMap(b *testing.B) {
        ns := newNs()
        m := map[string]int{"1": 10, "2": 20, "3": 30, "4": 40, "5": 50}
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                ns.Sort(context.Background(), m)
        }
 }
index 961d1d3678b04d943ec832eaabc6489b1c3c0813..d0fb469fee20ba15271034ad3e42a4f655eb4ae4 100644 (file)
@@ -42,7 +42,7 @@ func TestInspectCounts(t *testing.T) {
        const k = 10
        const iters = 10000
        counts := make([]int, max)
-       for i := 0; i < iters; i++ {
+       for range iters {
                testD(prng, t, k, max, func(n int) {
                        counts[n]++
                })
@@ -87,7 +87,7 @@ func BenchmarkD(b *testing.B) {
        // TODO: count rng calls?
        for _, want := range []int{1, 100, 10000} {
                b.Run(fmt.Sprintf("want=%d", want), func(b *testing.B) {
-                       for i := 0; i < b.N; i++ {
+                       for b.Loop() {
                                _d(prng, want, 1000000, func(int) {})
                        }
                })
index 6d53fc1ff26c26de1be0c5e69d7aca697ff2a1b8..3b55ffdbd51f136da4772ab1e35b25d0151f9cd2 100644 (file)
@@ -886,19 +886,19 @@ func BenchmarkWhereOps(b *testing.B) {
        }
 
        b.Run("eq", func(b *testing.B) {
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        runOps(b, "eq", "bar")
                }
        })
 
        b.Run("ne", func(b *testing.B) {
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        runOps(b, "ne", "baz")
                }
        })
 
        b.Run("like", func(b *testing.B) {
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        runOps(b, "like", "^bar")
                }
        })
@@ -912,7 +912,7 @@ func BenchmarkWhereMap(b *testing.B) {
                seq[fmt.Sprintf("key%d", i)] = "value"
        }
 
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                _, err := ns.Where(context.Background(), seq, "key", "eq", "value")
                if err != nil {
                        b.Fatal(err)
@@ -931,8 +931,8 @@ func BenchmarkWhereSliceOfStructPointersWithMethod(b *testing.B) {
                        seq = append(seq, &TstX{A: "baz", B: "qux"})
                }
        }
-       b.ResetTimer()
-       for range b.N {
+
+       for b.Loop() {
                _, err := ns.Where(context.Background(), seq, "TstRv2", "eq", "bar")
                if err != nil {
                        b.Fatal(err)
index ff5d59a9a038ebf32b5c8b4efe05dd53e35aed1c..d493aa16e50b2b2a3ec358addf244e400783f795 100644 (file)
@@ -43,7 +43,7 @@ func BenchmarkXxHash(b *testing.B) {
 
        runBench := func(name, input string, b *testing.B, fn func(v any)) {
                b.Run(fmt.Sprintf("%s_%d", name, len(input)), func(b *testing.B) {
-                       for i := 0; i < b.N; i++ {
+                       for b.Loop() {
                                fn(input)
                        }
                })
index e349ca7cdb8ee66fa375f2c50acbb974d39a4ebf..2790470fda00cf97b74cc62cc6dc6872a5e8203d 100644 (file)
@@ -716,7 +716,7 @@ func count(n int) chan string {
        }
        c := make(chan string)
        go func() {
-               for i := 0; i < n; i++ {
+               for i := range n {
                        c <- "abcdefghijklmnop"[i : i+1]
                }
                close(c)
@@ -1604,8 +1604,8 @@ func TestInterfaceValues(t *testing.T) {
                        "Nil":   nil,
                        "Zero":  0,
                })
-               if strings.HasPrefix(tt.out, "ERROR:") {
-                       e := strings.TrimSpace(strings.TrimPrefix(tt.out, "ERROR:"))
+               if after, ok := strings.CutPrefix(tt.out, "ERROR:"); ok {
+                       e := strings.TrimSpace(after)
                        if err == nil || !strings.Contains(err.Error(), e) {
                                t.Errorf("%s: Execute: %v, want error %q", tt.text, err, e)
                        }
@@ -1741,7 +1741,7 @@ func TestEscapeRace(t *testing.T) {
                t.Fatal(err)
        }
        const count = 20
-       for i := 0; i < count; i++ {
+       for i := range count {
                _, err := tmpl.New(fmt.Sprintf("x%d.html", i)).Parse(`{{ template "templ.html" .}}`)
                if err != nil {
                        t.Fatal(err)
@@ -1749,11 +1749,11 @@ func TestEscapeRace(t *testing.T) {
        }
 
        var wg sync.WaitGroup
-       for i := 0; i < 10; i++ {
+       for range 10 {
                wg.Add(1)
                go func() {
                        defer wg.Done()
-                       for j := 0; j < count; j++ {
+                       for j := range count {
                                sub := tmpl.Lookup(fmt.Sprintf("x%d.html", j))
                                if err := sub.Execute(io.Discard, nil); err != nil {
                                        t.Error(err)
index a46c8f5a82d23187bb6d85d43436c67b567d3bb5..e87ed1c9b226e0877abe563113ce4182cbd6d209 100644 (file)
@@ -121,7 +121,7 @@ func GoToolPath(t testing.TB) string {
        // Add all environment variables that affect the Go command to test metadata.
        // Cached test results will be invalidate when these variables change.
        // See golang.org/issue/32285.
-       for _, envVar := range strings.Fields(cfg.KnownEnv) {
+       for envVar := range strings.FieldsSeq(cfg.KnownEnv) {
                os.Getenv(envVar)
        }
        return path
@@ -415,7 +415,7 @@ func WriteImportcfg(t testing.TB, dstPath string, packageFiles map[string]string
                        t.Fatalf("%v: %v\n%s", cmd, err, cmd.Stderr)
                }
 
-               for _, line := range strings.Split(string(out), "\n") {
+               for line := range strings.SplitSeq(string(out), "\n") {
                        if line == "" {
                                continue
                        }
index afe1595319e16ff51a67a85c611d6ea0d855c6cf..87bcb1c7197d2b55d2e9395f3959f65dd37fe5ec 100644 (file)
@@ -172,8 +172,8 @@ func TestCleanCmdEnvPWD(t *testing.T) {
        cmd = testenv.CleanCmdEnv(cmd)
 
        for _, env := range cmd.Env {
-               if strings.HasPrefix(env, "PWD=") {
-                       pwd := strings.TrimPrefix(env, "PWD=")
+               if after, ok := strings.CutPrefix(env, "PWD="); ok {
+                       pwd := after
                        if pwd != dir {
                                t.Errorf("unexpected PWD: want %s, got %s", dir, pwd)
                        }
index 742e85605a7347727e54d32b1223d2c25707ba1e..b2cf3e7c6dc85680bb46bcea5042ed7b1813954f 100644 (file)
@@ -804,7 +804,7 @@ func count(n int) chan string {
        }
        c := make(chan string)
        go func() {
-               for i := 0; i < n; i++ {
+               for i := range n {
                        c <- "abcdefghijklmnop"[i : i+1]
                }
                close(c)
@@ -1714,8 +1714,8 @@ func TestInterfaceValues(t *testing.T) {
                        "Nil":   nil,
                        "Zero":  0,
                })
-               if strings.HasPrefix(tt.out, "ERROR:") {
-                       e := strings.TrimSpace(strings.TrimPrefix(tt.out, "ERROR:"))
+               if after, ok := strings.CutPrefix(tt.out, "ERROR:"); ok {
+                       e := strings.TrimSpace(after)
                        if err == nil || !strings.Contains(err.Error(), e) {
                                t.Errorf("%s: Execute: %v, want error %q", tt.text, err, e)
                        }
@@ -1940,7 +1940,7 @@ func TestIssue39807(t *testing.T) {
                wg.Add(1)
                go func() {
                        defer wg.Done()
-                       for j := 0; j < numTemplates; j++ {
+                       for range numTemplates {
                                _, err := tplFoo.AddParseTree(tplBar.Name(), tplBar.Tree)
                                if err != nil {
                                        t.Error(err)
index 7d63cf8b7bb6db3864672e162394d21d6090b83b..5318798ad375f1a40995b134711a64a399fdbba8 100644 (file)
@@ -8,6 +8,7 @@ import (
        "errors"
        "fmt"
        "io"
+       "maps"
        "net/url"
        "reflect"
        "strings"
@@ -103,9 +104,7 @@ func addValueFuncs(out map[string]reflect.Value, in FuncMap) {
 // addFuncs adds to values the functions in funcs. It does no checking of the input -
 // call addValueFuncs first.
 func addFuncs(out, in FuncMap) {
-       for name, fn := range in {
-               out[name] = fn
-       }
+       maps.Copy(out, in)
 }
 
 // goodFunc reports whether the function or method has the right result signature.
index 6b0e259c2312217872d54a26c52de411ed78bd19..37cd234d8316a39e255b95d35cb8fccd8cb7dfb0 100644 (file)
@@ -405,7 +405,7 @@ func (s *state) evalCall(dot, fun reflect.Value, isBuiltin bool, node parse.Node
        }
 
        // Added for Hugo
-       for i := 0; i < len(first); i++ {
+       for i := range first {
                argv[i] = s.validateType(first[i], typ.In(i))
        }
 
index e05a33d6fddac7ca8730a0f9565981e4493aec70..cc8a9336042dc1f6707fd7954045d16bf45fcb5c 100644 (file)
@@ -12,6 +12,7 @@ import (
        "bytes"
        "fmt"
        "runtime"
+       "slices"
        "strconv"
        "strings"
 )
@@ -821,10 +822,8 @@ func (t *Tree) popVars(n int) {
 // variable is not defined.
 func (t *Tree) useVar(pos Pos, name string) Node {
        v := t.newVariable(pos, name)
-       for _, varName := range t.vars {
-               if varName == v.Ident[0] {
-                       return v
-               }
+       if slices.Contains(t.vars, v.Ident[0]) {
+               return v
        }
        t.errorf("undefined variable %q", v.Ident[0])
        return nil
index a77b025ed8017a535d59e9a5d86d251e5b864de5..048ccbf90368f1c7d7a3effc0454bc4c80550dd9 100644 (file)
@@ -243,9 +243,7 @@ ABCDE
                builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
        }
 
-       b.ResetTimer()
-
-       for i := 0; i < b.N; i++ {
+       for i := 0; b.Loop(); i++ {
                builders[i].Build()
        }
 }
index eb5aee3cb05640388bfaeae590fff712cc1f254f..f80fdd98bb720dd00bde70abe2be8b0cf95965c4 100644 (file)
@@ -87,7 +87,7 @@ func (ns *Namespace) CountWords(s any) (int, error) {
        }
 
        counter := 0
-       for _, word := range strings.Fields(tpl.StripHTML(ss)) {
+       for word := range strings.FieldsSeq(tpl.StripHTML(ss)) {
                runeCount := utf8.RuneCountInString(word)
                if len(word) == runeCount {
                        counter++
index 633257456ed319e2d68d4be6ee7d24ac0128efb7..6a4db6c4a5bb3376cc5294c34f5f0597043ccaab 100644 (file)
@@ -114,13 +114,13 @@ func TestTruncate(t *testing.T) {
 
 func BenchmarkTruncate(b *testing.B) {
        b.Run("Plain text", func(b *testing.B) {
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        ns.Truncate(10, "I am a test sentence")
                }
        })
 
        b.Run("With link", func(b *testing.B) {
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        ns.Truncate(10, "I have a <a href='/markdown'>Markdown link</a> inside")
                }
        })
index 622f1b12da6bc4a48de815fe33ecd614400c1960..a0989d78f8a521e6ffb1d366fe7c52e16f2d690d 100644 (file)
@@ -248,7 +248,7 @@ func BenchmarkInWithCaching(b *testing.B) {
 
        ns := time.New(htime.NewTimeFormatter(translators.GetTranslator("en")), gtime.UTC, bb.H.Deps)
 
-       for i := 0; i < b.N; i++ {
+       for i := 0; b.Loop(); i++ {
                timeZoneName := timeZoneNames[i%len(timeZoneNames)]
                _, err := ns.In(timeZoneName, gtime.Now())
                if err != nil {
@@ -258,7 +258,7 @@ func BenchmarkInWithCaching(b *testing.B) {
 }
 
 func BenchmarkInWithoutCaching(b *testing.B) {
-       for i := 0; i < b.N; i++ {
+       for i := 0; b.Loop(); i++ {
                timeZoneName := timeZoneNames[i%len(timeZoneNames)]
                location, err := gtime.LoadLocation(timeZoneName)
                if err != nil {
index ed8763c87657edf627373f581710a1e197af774b..986e05481e78d01c98ff5b44c7a7fda91c8ce2c6 100644 (file)
@@ -95,8 +95,7 @@ func BenchmarkCompareDescriptors(b *testing.B) {
                },
        }
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                for _, pair := range pairs {
                        _ = dh.compareDescriptors(CategoryLayout, pair.d1, pair.d2, nil, nil)
                }
index 90fc9614bcf35f048e082cb196818e332c77a060..3dcc70103d4472130e6d88925582bcf6e529a20f 100644 (file)
@@ -740,7 +740,7 @@ baseof: {{ block "main" . }}{{ end }}
                        Category: tplimpl.CategoryLayout,
                        Desc:     tplimpl.TemplateDescriptor{Kind: kinds.KindPage, LayoutFromTemplate: "single", OutputFormat: "html"},
                }
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        store.LookupPagesLayout(q)
                }
        })
@@ -751,7 +751,7 @@ baseof: {{ block "main" . }}{{ end }}
                        Category: tplimpl.CategoryLayout,
                        Desc:     tplimpl.TemplateDescriptor{Kind: kinds.KindPage, LayoutFromTemplate: "single", OutputFormat: "html"},
                }
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        store.LookupPagesLayout(q)
                }
        })
@@ -761,8 +761,7 @@ func BenchmarkNewTemplateStore(b *testing.B) {
        bb := hugolib.Test(b, newSetupTestSites)
        store := bb.H.TemplateStore
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                newStore, err := store.NewFromOpts()
                if err != nil {
                        b.Fatal(err)
@@ -1416,8 +1415,7 @@ p3
        p := bb.H.Sites[0].RegularPages()[0]
        bb.Assert(p, qt.Not(qt.IsNil))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                err := store.ExecuteWithContext(context.Background(), ti, io.Discard, p)
                if err != nil {
                        b.Fatal(err)
@@ -1440,7 +1438,7 @@ disableKinds = ["taxonomy", "term", "home"]
 
        store := bb.H.TemplateStore
 
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                fi := store.LookupPartial("p3.html")
                if fi == nil {
                        b.Fatal("not found")
@@ -1486,14 +1484,14 @@ s2.
 
        b.Run("toplevelpage", func(b *testing.B) {
                toplevelpage, _ := bb.H.Sites[0].GetPage("/toplevelpage")
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        runOne(toplevelpage)
                }
        })
 
        b.Run("nestedpage", func(b *testing.B) {
                toplevelpage, _ := bb.H.Sites[0].GetPage("/a/b/c/nested")
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        runOne(toplevelpage)
                }
        })
index 934b29ee1235cd1b094de9dde94c2126f6964fa8..3d60dcda71308346c2b6c90c5c977ff0927353ed 100644 (file)
@@ -206,8 +206,7 @@ func BenchmarkUnmarshalString(b *testing.B) {
 
        ctx := context.Background()
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                result, err := ns.Unmarshal(ctx, jsons[rand.Intn(numJsons)])
                if err != nil {
                        b.Fatal(err)
@@ -235,8 +234,7 @@ func BenchmarkUnmarshalResource(b *testing.B) {
 
        ctx := context.Background()
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                result, err := ns.Unmarshal(ctx, jsons[rand.Intn(numJsons)])
                if err != nil {
                        b.Fatal(err)
index 5475fc5b6e97e21245cb9bc46edd20f831a713b6..8433461068877170cb09c9369bf39f366251023c 100644 (file)
@@ -136,8 +136,7 @@ func BenchmarkLiveReloadInject(b *testing.B) {
        }
        tr := transform.New(New(lrurl))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                in.Seek(0, 0)
                tr.Apply(io.Discard, in)
        }
index f95ee4fc14359f0d34a8ba0db0ba5354f0e5a088..b8652afed017d090dd7e6e7515d32d9c85eca5bc 100644 (file)
@@ -125,8 +125,7 @@ var (
 func BenchmarkAbsURL(b *testing.B) {
        tr := transform.New(NewAbsURLTransformer(testBaseURL))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                apply(b.Errorf, tr, absURLlBenchTests)
        }
 }
@@ -134,8 +133,7 @@ func BenchmarkAbsURL(b *testing.B) {
 func BenchmarkAbsURLSrcset(b *testing.B) {
        tr := transform.New(NewAbsURLTransformer(testBaseURL))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                apply(b.Errorf, tr, srcsetTests)
        }
 }
@@ -143,8 +141,7 @@ func BenchmarkAbsURLSrcset(b *testing.B) {
 func BenchmarkXMLAbsURLSrcset(b *testing.B) {
        tr := transform.New(NewAbsURLInXMLTransformer(testBaseURL))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                apply(b.Errorf, tr, srcsetXMLTests)
        }
 }
@@ -191,8 +188,7 @@ func TestAbsXMLURLSrcSet(t *testing.T) {
 func BenchmarkXMLAbsURL(b *testing.B) {
        tr := transform.New(NewAbsURLInXMLTransformer(testBaseURL))
 
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
+       for b.Loop() {
                apply(b.Errorf, tr, xmlAbsURLBenchTests)
        }
 }
index 77feb459d1c940006fea2ba0dab5662e4e01b2af..39c92f01e57a2cc6dd4df4d2f49b64c281f82774 100644 (file)
@@ -185,7 +185,7 @@ func TestCheckChange(t *testing.T) {
 func BenchmarkPoller(b *testing.B) {
        runBench := func(b *testing.B, item *itemToWatch) {
                b.ResetTimer()
-               for i := 0; i < b.N; i++ {
+               for b.Loop() {
                        evs, err := item.checkForChanges()
                        if err != nil {
                                b.Fatal(err)