Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cache/httpcache/httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
19 changes: 8 additions & 11 deletions common/hashing/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -75,25 +74,25 @@ 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)
}
}

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)
}
}
Expand Down Expand Up @@ -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)
}
})
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion common/hreflect/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
15 changes: 6 additions & 9 deletions common/hreflect/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions common/hstore/scratch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
14 changes: 7 additions & 7 deletions common/hstrings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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+`)
}
}
2 changes: 1 addition & 1 deletion common/hsync/oncemore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions common/htime/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion common/maps/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
14 changes: 7 additions & 7 deletions common/maps/orderedintset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,47 @@ 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
})
}
})

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
})
}
})

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
})
Expand Down
1 change: 0 additions & 1 deletion common/para/para_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions common/paths/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions common/paths/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions common/paths/pathparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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)
}
}
Loading
Loading