| 505 | } |
| 506 | |
| 507 | func (c *coster) costSelect(e ast.Expr) CostEstimate { |
| 508 | sel := e.AsSelect() |
| 509 | var sum CostEstimate |
| 510 | if sel.IsTestOnly() { |
| 511 | // recurse, but do not add any cost |
| 512 | // this is equivalent to how evalTestOnly increments the runtime cost counter |
| 513 | // but does not add any additional cost for the qualifier, except here we do |
| 514 | // the reverse (ident adds cost) |
| 515 | sum = sum.Add(c.presenceTestCost) |
| 516 | sum = sum.Add(c.cost(sel.Operand())) |
| 517 | return sum |
| 518 | } |
| 519 | sum = sum.Add(c.cost(sel.Operand())) |
| 520 | targetType := c.getType(sel.Operand()) |
| 521 | switch targetType.Kind() { |
| 522 | case types.MapKind, types.StructKind, types.TypeParamKind: |
| 523 | sum = sum.Add(selectAndIdentCost) |
| 524 | } |
| 525 | |
| 526 | // build and track the field path |
| 527 | c.addPath(e, append(c.getPath(sel.Operand()), sel.FieldName())) |
| 528 | return sum |
| 529 | } |
| 530 | |
| 531 | func (c *coster) costCall(e ast.Expr) CostEstimate { |
| 532 | // Dyn is just a way to disable type-checking, so return the cost of 1 with the cost of the argument |