this repo has no description
0
fork

Configure Feed

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

internal/core/convert: avoid repeated OpContext.Env calls

They're also only used for adt.MakeRootConjunct,
which happily uses an empty environment when none is given.

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

+5 -20
+5 -20
internal/core/convert/go.go
··· 206 206 } 207 207 return &adt.Null{Src: src} 208 208 } 209 + env := ctx.Env(0) 209 210 typ := val.Type() 210 211 switch typ { 211 212 case astFile: ··· 400 401 401 402 f := ctx.StringLabel(name) 402 403 sl.Decls = append(sl.Decls, &adt.Field{Label: f, Value: sub}) 403 - v.Arcs = append(v.Arcs, ensureArcVertex(ctx, sub, f)) 404 + v.Arcs = append(v.Arcs, ensureArcVertex(ctx, env, sub, f)) 404 405 } 405 406 406 - env := ctx.Env(0) 407 - if env == nil { 408 - env = &adt.Environment{} 409 - } 410 407 // There is no closedness or cycle info for Go structs, so we pass an empty CloseInfo. 411 408 v.AddStruct(sl, env, adt.CloseInfo{}) 412 409 v.SetValue(ctx, &adt.StructMarker{}) ··· 442 439 443 440 s := fmt.Sprint(k) 444 441 f := ctx.StringLabel(s) 445 - v.Arcs = append(v.Arcs, ensureArcVertex(ctx, sub, f)) 442 + v.Arcs = append(v.Arcs, ensureArcVertex(ctx, env, sub, f)) 446 443 } 447 444 slices.SortFunc(v.Arcs, func(a, b *adt.Vertex) int { 448 445 return strings.Compare(a.Label.IdentString(ctx), b.Label.IdentString(ctx)) ··· 453 450 } 454 451 } 455 452 456 - env := ctx.Env(0) 457 - if env == nil { 458 - env = &adt.Environment{} 459 - } 460 453 v.AddStruct(obj, env, adt.CloseInfo{}) 461 454 v.SetValue(ctx, &adt.StructMarker{}) 462 455 v.ForceDone() ··· 495 488 } 496 489 list.Elems = append(list.Elems, x) 497 490 f := adt.MakeIntLabel(adt.IntLabel, int64(i)) 498 - v.Arcs = append(v.Arcs, ensureArcVertex(ctx, x, f)) 491 + v.Arcs = append(v.Arcs, ensureArcVertex(ctx, env, x, f)) 499 492 } 500 493 501 - env := ctx.Env(0) 502 - if env == nil { 503 - env = &adt.Environment{} 504 - } 505 494 v.AddConjunct(adt.MakeRootConjunct(env, list)) 506 495 v.SetValue(ctx, &adt.ListMarker{}) 507 496 v.ForceDone() ··· 521 510 return *apd.NewWithBigInt(new(apd.BigInt).SetMathBigInt(x), 0) 522 511 } 523 512 524 - func ensureArcVertex(ctx *adt.OpContext, x adt.Value, l adt.Feature) *adt.Vertex { 513 + func ensureArcVertex(ctx *adt.OpContext, env *adt.Environment, x adt.Value, l adt.Feature) *adt.Vertex { 525 514 if arc, ok := x.(*adt.Vertex); ok { 526 515 if arc.Label == l { 527 516 // We already have a vertex with the correct label; do not make a copy. ··· 531 520 a := *arc 532 521 a.Label = l 533 522 return &a 534 - } 535 - env := ctx.Env(0) 536 - if env == nil { 537 - env = &adt.Environment{} 538 523 } 539 524 arc := &adt.Vertex{Label: l} 540 525 arc.AddConjunct(adt.MakeRootConjunct(env, x))