this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/adt: do not allocate a new YieldFunc in processComprehension

We can use a method on the already allocated envComprehension,
whose pointer value is embedded into envYield.

As a bonus, the code is a bit shorter now.

│ old │ new │
│ B/op │ B/op vs base │
VetInventory 4.765Gi ± ∞ ¹ 4.752Gi ± ∞ ¹ -0.26% (p=1.000 n=1)

│ old │ new │
│ allocs/op │ allocs/op vs base │
VetInventory 53.42M ± ∞ ¹ 52.86M ± ∞ ¹ -1.05% (p=1.000 n=1)

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ied7155f0a37b03eb65470b11ac02e7e3610760bc
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1229422
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+7 -8
+7 -8
internal/core/adt/comprehension.go
··· 87 87 structs []*StructLit 88 88 } 89 89 90 + // addEnv is used as a [YieldFunc] so that we don't need to create a new func 91 + // value for each comprehension. 92 + func (e *envComprehension) addEnv(env *Environment) { 93 + e.envs = append(e.envs, env) 94 + } 95 + 90 96 // envYield defines a comprehension for a specific field within a comprehension 91 97 // value. Multiple envYields can be associated with a single envComprehension. 92 98 // An envComprehension only needs to be evaluated once for multiple envYields. ··· 334 340 335 341 // Compute environments, if needed. 336 342 if !d.done { 337 - var envs []*Environment 338 - f := func(env *Environment) { 339 - envs = append(envs, env) 340 - } 341 - 342 343 if err := ctx.yield(d.vertex, d.env, d.comp, Flags{ 343 344 status: state, 344 345 condition: allKnown, 345 346 mode: ignore, 346 - }, f); err != nil { 347 + }, d.addEnv); err != nil { 347 348 if err.IsIncomplete() { 348 349 return err 349 350 } ··· 357 358 } 358 359 return nil 359 360 } 360 - 361 - d.envs = envs 362 361 363 362 if len(d.envs) > 0 { 364 363 for _, s := range d.structs {