newFastValuesCtx returns a new context with the given parent and the values from the ancestor. If the ancestor has an associated container that has free slots, it is used to avoid a new allocation.
(ancestor *fastValuesCtx, parent context.Context)
| 166 | // If the ancestor has an associated container that has free slots, it is used |
| 167 | // to avoid a new allocation. |
| 168 | func newFastValuesCtx(ancestor *fastValuesCtx, parent context.Context) *fastValuesCtx { |
| 169 | var ctx *fastValuesCtx |
| 170 | var container *fastValuesContainer |
| 171 | if ancestor != nil && ancestor.container != nil { |
| 172 | // Try to use the container. |
| 173 | var more bool |
| 174 | ctx, more = ancestor.container.get() |
| 175 | if more { |
| 176 | container = ancestor.container |
| 177 | } else if ctx == nil { |
| 178 | ctx = &fastValuesCtx{} |
| 179 | } |
| 180 | } else { |
| 181 | ctx = &fastValuesCtx{} |
| 182 | } |
| 183 | ctx.init(parent, container, ancestor) |
| 184 | return ctx |
| 185 | } |
| 186 | |
| 187 | // findFastValuesCtxAncestor returns the closest fastValuesCtx ancestor of the |
| 188 | // given parent context. |
no test coverage detected
searching dependent graphs…