mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 22:13:39 +00:00
all: modernize (#5498)
* modernize string cut usage * modernize string cut prefix usage * modernize slices helper usage * modernize min and max usage * modernize loop variable copies * modernize integer range loops * modernize map copy loops * modernize go types iterator usage * modernize empty interface usage * modernize atomic type usage * modernize string builders * modernize string split iteration * modernize remaining loop variable copies * modernize usb cdc min usage * modernize src integer range loops * modernize example empty interface usage * modernize src min and max usage * modernize src integer range loops * modernize src empty interface usage * modernize src atomic type usage * modernize reflect type lookups * modernize review nits
This commit is contained in:
@@ -150,11 +150,11 @@ func (p *lowerInterfacesPass) run() error {
|
||||
|
||||
// Collect all type codes.
|
||||
for global := p.mod.FirstGlobal(); !global.IsNil(); global = llvm.NextGlobal(global) {
|
||||
if strings.HasPrefix(global.Name(), "reflect/types.type:") {
|
||||
if after, ok := strings.CutPrefix(global.Name(), "reflect/types.type:"); ok {
|
||||
// Retrieve Go type information based on an opaque global variable.
|
||||
// Only the name of the global is relevant, the object itself is
|
||||
// discarded afterwards.
|
||||
name := strings.TrimPrefix(global.Name(), "reflect/types.type:")
|
||||
name := after
|
||||
if _, ok := p.types[name]; !ok {
|
||||
t := &typeInfo{
|
||||
name: name,
|
||||
@@ -463,7 +463,7 @@ func (p *lowerInterfacesPass) addTypeMethods(t *typeInfo, methodSet llvm.Value)
|
||||
signatures := p.builder.CreateExtractValue(set, 1, "")
|
||||
wrappers := p.builder.CreateExtractValue(set, 2, "")
|
||||
numMethods := signatures.Type().ArrayLength()
|
||||
for i := 0; i < numMethods; i++ {
|
||||
for i := range numMethods {
|
||||
signatureGlobal := p.builder.CreateExtractValue(signatures, i, "")
|
||||
function := p.builder.CreateExtractValue(wrappers, i, "")
|
||||
function = stripPointerCasts(function) // strip bitcasts
|
||||
@@ -489,7 +489,7 @@ func (p *lowerInterfacesPass) addInterface(methodsString string) {
|
||||
signatures: make(map[string]*signatureInfo),
|
||||
}
|
||||
p.interfaces[methodsString] = t
|
||||
for _, method := range strings.Split(methodsString, "; ") {
|
||||
for method := range strings.SplitSeq(methodsString, "; ") {
|
||||
signature := p.getSignature(method)
|
||||
signature.interfaces = append(signature.interfaces, t)
|
||||
t.signatures[method] = signature
|
||||
@@ -683,7 +683,7 @@ func (p *lowerInterfacesPass) extractMethodSigs(field llvm.Value) []string {
|
||||
methodArray := p.builder.CreateExtractValue(field, 1, "")
|
||||
n := methodArray.Type().ArrayLength()
|
||||
sigs := make([]string, 0, n)
|
||||
for j := 0; j < n; j++ {
|
||||
for j := range n {
|
||||
sig := p.builder.CreateExtractValue(methodArray, j, "")
|
||||
sig = stripPointerCasts(sig)
|
||||
sigs = append(sigs, sig.Name())
|
||||
@@ -727,7 +727,7 @@ func (p *lowerInterfacesPass) filterMethodSet(field llvm.Value, keepSigs map[str
|
||||
}
|
||||
entries := make([]methodEntry, numMethods)
|
||||
nameSet := make(map[string]struct{}, numMethods)
|
||||
for j := 0; j < numMethods; j++ {
|
||||
for j := range numMethods {
|
||||
sig := p.builder.CreateExtractValue(methodArray, j, "")
|
||||
stripped := stripPointerCasts(sig)
|
||||
name := stripped.Name()
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ func hasUses(value llvm.Value) bool {
|
||||
// contents, and returns the global and initializer type.
|
||||
// Note that it is left with the default linkage etc., you should set
|
||||
// linkage/constant/etc properties yourself.
|
||||
func makeGlobalArray(mod llvm.Module, bufItf interface{}, name string, elementType llvm.Type) (llvm.Type, llvm.Value) {
|
||||
func makeGlobalArray(mod llvm.Module, bufItf any, name string, elementType llvm.Type) (llvm.Type, llvm.Value) {
|
||||
buf := reflect.ValueOf(bufItf)
|
||||
var values []llvm.Value
|
||||
for i := 0; i < buf.Len(); i++ {
|
||||
@@ -64,7 +64,7 @@ func getGlobalBytes(global llvm.Value, builder llvm.Builder) []byte {
|
||||
// replaceGlobalByteWithArray replaces a global integer type in the module with
|
||||
// an integer array, using a GEP to make the types match. It is a convenience
|
||||
// function used for creating reflection sidetables, for example.
|
||||
func replaceGlobalIntWithArray(mod llvm.Module, name string, buf interface{}) llvm.Value {
|
||||
func replaceGlobalIntWithArray(mod llvm.Module, name string, buf any) llvm.Value {
|
||||
oldGlobal := mod.NamedGlobal(name)
|
||||
globalType, global := makeGlobalArray(mod, buf, name+".tmp", oldGlobal.GlobalValueType())
|
||||
gep := llvm.ConstGEP(globalType, global, []llvm.Value{
|
||||
|
||||
Reference in New Issue
Block a user