Merge a5d4feb09864951fabd1fb5bb386a6142f93be20 into c3d1092b3b48addf6f9cd00fe274ec3bd14650eb

This commit is contained in:
613 2025-10-13 05:34:26 +00:00 committed by GitHub
commit 2432bd9de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 19 additions and 19 deletions

View File

@ -154,7 +154,7 @@ func runRequest(B *testing.B, r *Engine, method, path string) {
w := newMockWriter() w := newMockWriter()
B.ReportAllocs() B.ReportAllocs()
B.ResetTimer() B.ResetTimer()
for i := 0; i < B.N; i++ { for B.Loop() {
r.ServeHTTP(w, req) r.ServeHTTP(w, req)
} }
} }

View File

@ -27,7 +27,7 @@ func (err SliceValidationError) Error() string {
} }
var b strings.Builder var b strings.Builder
for i := 0; i < len(err); i++ { for i := range len(err) {
if err[i] != nil { if err[i] != nil {
if b.Len() > 0 { if b.Len() > 0 {
b.WriteString("\n") b.WriteString("\n")
@ -58,7 +58,7 @@ func (v *defaultValidator) ValidateStruct(obj any) error {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:
count := value.Len() count := value.Len()
validateRet := make(SliceValidationError, 0) validateRet := make(SliceValidationError, 0)
for i := 0; i < count; i++ { for i := range count {
if err := v.ValidateStruct(value.Index(i).Interface()); err != nil { if err := v.ValidateStruct(value.Index(i).Interface()); err != nil {
validateRet = append(validateRet, err) validateRet = append(validateRet, err)
} }

View File

@ -20,7 +20,7 @@ func BenchmarkSliceValidationError(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for b.Loop() {
if len(e.Error()) == 0 { if len(e.Error()) == 0 {
b.Errorf("error") b.Errorf("error")
} }

View File

@ -118,7 +118,7 @@ func mapping(value reflect.Value, field reflect.StructField, setter setter, tag
tValue := value.Type() tValue := value.Type()
var isSet bool var isSet bool
for i := 0; i < value.NumField(); i++ { for i := range value.NumField() {
sf := tValue.Field(i) sf := tValue.Field(i)
if sf.PkgPath != "" && !sf.Anonymous { // unexported if sf.PkgPath != "" && !sf.Anonymous { // unexported
continue continue

View File

@ -31,7 +31,7 @@ type structFull struct {
func BenchmarkMapFormFull(b *testing.B) { func BenchmarkMapFormFull(b *testing.B) {
var s structFull var s structFull
for i := 0; i < b.N; i++ { for b.Loop() {
err := mapForm(&s, form) err := mapForm(&s, form)
if err != nil { if err != nil {
b.Fatalf("Error on a form mapping") b.Fatalf("Error on a form mapping")
@ -54,7 +54,7 @@ type structName struct {
func BenchmarkMapFormName(b *testing.B) { func BenchmarkMapFormName(b *testing.B) {
var s structName var s structName
for i := 0; i < b.N; i++ { for b.Loop() {
err := mapForm(&s, form) err := mapForm(&s, form)
if err != nil { if err != nil {
b.Fatalf("Error on a form mapping") b.Fatalf("Error on a form mapping")

View File

@ -3581,22 +3581,22 @@ func BenchmarkGetMapFromFormData(b *testing.B) {
// Test case 3: Large dataset with many bracket keys // Test case 3: Large dataset with many bracket keys
largeData := make(map[string][]string) largeData := make(map[string][]string)
for i := 0; i < 100; i++ { for i := range 100 {
key := fmt.Sprintf("ids[%d]", i) key := fmt.Sprintf("ids[%d]", i)
largeData[key] = []string{fmt.Sprintf("value%d", i)} largeData[key] = []string{fmt.Sprintf("value%d", i)}
} }
for i := 0; i < 50; i++ { for i := range 50 {
key := fmt.Sprintf("names[%d]", i) key := fmt.Sprintf("names[%d]", i)
largeData[key] = []string{fmt.Sprintf("name%d", i)} largeData[key] = []string{fmt.Sprintf("name%d", i)}
} }
for i := 0; i < 25; i++ { for i := range 25 {
key := fmt.Sprintf("other[key%d]", i) key := fmt.Sprintf("other[key%d]", i)
largeData[key] = []string{fmt.Sprintf("other%d", i)} largeData[key] = []string{fmt.Sprintf("other%d", i)}
} }
// Test case 4: Dataset with many non-matching keys (worst case) // Test case 4: Dataset with many non-matching keys (worst case)
worstCaseData := make(map[string][]string) worstCaseData := make(map[string][]string)
for i := 0; i < 100; i++ { for i := range 100 {
key := fmt.Sprintf("nonmatching%d", i) key := fmt.Sprintf("nonmatching%d", i)
worstCaseData[key] = []string{fmt.Sprintf("value%d", i)} worstCaseData[key] = []string{fmt.Sprintf("value%d", i)}
} }
@ -3632,7 +3632,7 @@ func BenchmarkGetMapFromFormData(b *testing.B) {
for _, bm := range benchmarks { for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) { b.Run(bm.name, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for b.Loop() {
_, _ = getMapFromFormData(bm.data, bm.key) _, _ = getMapFromFormData(bm.data, bm.key)
} }
}) })

View File

@ -393,7 +393,7 @@ func TestConcurrentHandleContext(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
iterations := 200 iterations := 200
wg.Add(iterations) wg.Add(iterations)
for i := 0; i < iterations; i++ { for range iterations {
go func() { go func() {
req, err := http.NewRequest(http.MethodGet, "/", nil) req, err := http.NewRequest(http.MethodGet, "/", nil)
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -30,7 +30,7 @@ func rawStrToBytes(s string) []byte {
func TestBytesToString(t *testing.T) { func TestBytesToString(t *testing.T) {
data := make([]byte, 1024) data := make([]byte, 1024)
for i := 0; i < 100; i++ { for range 100 {
_, err := cRand.Read(data) _, err := cRand.Read(data)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -70,7 +70,7 @@ func RandStringBytesMaskImprSrcSB(n int) string {
} }
func TestStringToBytes(t *testing.T) { func TestStringToBytes(t *testing.T) {
for i := 0; i < 100; i++ { for range 100 {
s := RandStringBytesMaskImprSrcSB(64) s := RandStringBytesMaskImprSrcSB(64)
if !bytes.Equal(rawStrToBytes(s), StringToBytes(s)) { if !bytes.Equal(rawStrToBytes(s), StringToBytes(s)) {
t.Fatal("don't match") t.Fatal("don't match")

View File

@ -94,7 +94,7 @@ func TestPathCleanMallocs(t *testing.T) {
func BenchmarkPathClean(b *testing.B) { func BenchmarkPathClean(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for b.Loop() {
for _, test := range cleanTests { for _, test := range cleanTests {
cleanPath(test.path) cleanPath(test.path)
} }
@ -137,7 +137,7 @@ func BenchmarkPathCleanLong(b *testing.B) {
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for b.Loop() {
for _, test := range cleanTests { for _, test := range cleanTests {
cleanPath(test.path) cleanPath(test.path)
} }

View File

@ -155,7 +155,7 @@ func resolveAddress(addr []string) string {
// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters // https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters
func isASCII(s string) bool { func isASCII(s string) bool {
for i := 0; i < len(s); i++ { for i := range len(s) {
if s[i] > unicode.MaxASCII { if s[i] > unicode.MaxASCII {
return false return false
} }

View File

@ -19,7 +19,7 @@ func init() {
} }
func BenchmarkParseAccept(b *testing.B) { func BenchmarkParseAccept(b *testing.B) {
for i := 0; i < b.N; i++ { for b.Loop() {
parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8") parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
} }
} }