propInline identifies and inlines candidates
()
| 88 | |
| 89 | // propInline identifies and inlines candidates |
| 90 | func (fs *FileSet) propInline() { |
| 91 | type gelem struct { |
| 92 | name string |
| 93 | el gen.Elem |
| 94 | } |
| 95 | |
| 96 | all := make([]gelem, 0, len(fs.Identities)) |
| 97 | |
| 98 | for name, el := range fs.Identities { |
| 99 | all = append(all, gelem{name: name, el: el}) |
| 100 | } |
| 101 | |
| 102 | // make sure we process inlining determinstically: |
| 103 | // start with the least-complex elems; |
| 104 | // use identifier names as a tie-breaker |
| 105 | sort.Slice(all, func(i, j int) bool { |
| 106 | ig, jg := &all[i], &all[j] |
| 107 | ic, jc := ig.el.Complexity(), jg.el.Complexity() |
| 108 | return ic < jc || (ic == jc && ig.name < jg.name) |
| 109 | }) |
| 110 | |
| 111 | for i := range all { |
| 112 | name := all[i].name |
| 113 | pushstate(name) |
| 114 | switch el := all[i].el.(type) { |
| 115 | case *gen.Struct: |
| 116 | for i := range el.Fields { |
| 117 | fs.nextInline(&el.Fields[i].FieldElem, name, el.TypeParams()) |
| 118 | } |
| 119 | case *gen.Array: |
| 120 | fs.nextInline(&el.Els, name, el.TypeParams()) |
| 121 | case *gen.Slice: |
| 122 | fs.nextInline(&el.Els, name, el.TypeParams()) |
| 123 | case *gen.Map: |
| 124 | fs.nextInline(&el.Value, name, el.TypeParams()) |
| 125 | case *gen.Ptr: |
| 126 | fs.nextInline(&el.Value, name, el.TypeParams()) |
| 127 | } |
| 128 | popstate() |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | const fatalloop = `detected infinite recursion in inlining loop! |
| 133 | Please file a bug at github.com/tinylib/msgp/issues! |
no test coverage detected