def visit
bend-lint-rules@0.2.0.0 · performance/repeated_call.bend:125
import bend-lint-rules@0.2.0.0/performance/repeated_call.bend as RepeatedCall
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint
import bend-lint-api@0.2.0.0/shared/names.bend as Names
import bend-lint-rules@0.2.0.0/performance/loop_invariant_call.bend as Invariant
125
126def visit(+scope: Scope, +path: List<&2, Lint.Above>, +node: Lint.Node) -> List<&2, Call>:
127 match scope node:
128 case Scope{
129 Invariant.Owner{+loops, target, name, fixed},
130 defs
131 } Lint.Node{
132 Lint.Application{},
133 n,
134 Some{span},
135 Con{Lint.Node{Lint.Reference{+t}, callee, rs, rk, rf}, args},
136 f
137 }:
138 Bool.pick(
139 List<&2, Call>,
140 is_kept(
141 List.contains(
142 ~String,
143 ~String.eq,
144 loops,
145 t
146 )
147 && returns_number(Names.find(Lint.Def, defs, t))
148 && Lint.is_live(path)
149 && Bool.not(is_guarded(path, False{})),
150 Invariant.Owner{loops, target, name, fixed},
151 path,
152 node
153 ),
154 [Call{t, callee, args, span, branch.at(Invariant.branch(path, None{}))}],
155 []
156 )
157 case _ _:
158 []