| 81 | } |
| 82 | |
| 83 | func (c *typeCache) generate(typ reflect.Type, tags rlpstruct.Tags) *typeinfo { |
| 84 | c.mu.Lock() |
| 85 | defer c.mu.Unlock() |
| 86 | |
| 87 | cur := c.cur.Load().(map[typekey]*typeinfo) |
| 88 | if info := cur[typekey{typ, tags}]; info != nil { |
| 89 | return info |
| 90 | } |
| 91 | |
| 92 | // Copy cur to next. |
| 93 | c.next = make(map[typekey]*typeinfo, len(cur)+1) |
| 94 | for k, v := range cur { |
| 95 | c.next[k] = v |
| 96 | } |
| 97 | |
| 98 | // Generate. |
| 99 | info := c.infoWhileGenerating(typ, tags) |
| 100 | |
| 101 | // next -> cur |
| 102 | c.cur.Store(c.next) |
| 103 | c.next = nil |
| 104 | return info |
| 105 | } |
| 106 | |
| 107 | func (c *typeCache) infoWhileGenerating(typ reflect.Type, tags rlpstruct.Tags) *typeinfo { |
| 108 | key := typekey{typ, tags} |