internal/literals: modernize -fix

pull/955/merge
Daniel Martí 1 month ago
parent 36fcc61c4e
commit cb4cb3cfca

@ -160,7 +160,7 @@ func randExtKey(rand *mathrand.Rand, idx int) *externalKey {
func randExtKeys(rand *mathrand.Rand) []*externalKey { func randExtKeys(rand *mathrand.Rand) []*externalKey {
count := minExtKeyCount + rand.Intn(maxExtKeyCount-minExtKeyCount) count := minExtKeyCount + rand.Intn(maxExtKeyCount-minExtKeyCount)
keys := make([]*externalKey, count) keys := make([]*externalKey, count)
for i := 0; i < count; i++ { for i := range count {
keys[i] = randExtKey(rand, i) keys[i] = randExtKey(rand, i)
} }
return keys return keys
@ -211,7 +211,7 @@ func dataToByteSliceWithExtKeys(rand *mathrand.Rand, data []byte, extKeys []*ext
extKeyOpCount := minByteSliceExtKeyOps + rand.Intn(maxByteSliceExtKeyOps-minByteSliceExtKeyOps) extKeyOpCount := minByteSliceExtKeyOps + rand.Intn(maxByteSliceExtKeyOps-minByteSliceExtKeyOps)
var stmts []ast.Stmt var stmts []ast.Stmt
for i := 0; i < extKeyOpCount; i++ { for range extKeyOpCount {
key := extKeys[rand.Intn(len(extKeys))] key := extKeys[rand.Intn(len(extKeys))]
key.AddRef() key.AddRef()

@ -54,7 +54,7 @@ type proxyDispatcher struct {
func (d *proxyDispatcher) initialize() { func (d *proxyDispatcher) initialize() {
flattenStructs := make([]*proxyStruct, d.rand.Intn(maxStructCount-minStructCount)+minStructCount) flattenStructs := make([]*proxyStruct, d.rand.Intn(maxStructCount-minStructCount)+minStructCount)
for i := 0; i < len(flattenStructs); i++ { for i := range flattenStructs {
flattenStructs[i] = &proxyStruct{ flattenStructs[i] = &proxyStruct{
typeName: d.nameFunc(d.rand, "proxyStructName"+strconv.Itoa(i)), typeName: d.nameFunc(d.rand, "proxyStructName"+strconv.Itoa(i)),
name: d.nameFunc(d.rand, "proxyStructFieldName"+strconv.Itoa(i)), name: d.nameFunc(d.rand, "proxyStructFieldName"+strconv.Itoa(i)),
@ -75,10 +75,7 @@ func (d *proxyDispatcher) initialize() {
current := queue[0] current := queue[0]
queue = queue[1:] queue = queue[1:]
childCount := d.rand.Intn(maxChildCount-minChildCount) + minChildCount childCount := min(d.rand.Intn(maxChildCount-minChildCount)+minChildCount, len(unassigned))
if childCount > len(unassigned) {
childCount = len(unassigned)
}
for i := 0; i < childCount; i++ { for i := 0; i < childCount; i++ {
child := unassigned[0] child := unassigned[0]
@ -194,7 +191,7 @@ func (d *proxyDispatcher) AddToFile(file *ast.File) {
for _, strct := range d.flattenStructs { for _, strct := range d.flattenStructs {
dummyCount := d.rand.Intn(maxJunkValueCount-minJunkValueCount+1) + minJunkValueCount dummyCount := d.rand.Intn(maxJunkValueCount-minJunkValueCount+1) + minJunkValueCount
for i := 0; i < dummyCount; i++ { for range dummyCount {
strct.values = append(strct.values, d.junkValue()) strct.values = append(strct.values, d.junkValue())
} }

Loading…
Cancel
Save