~/bend-docscommunity

performance/list_index_loop.bend fails

raw source on the hub · import bend-lint-rules@0.1.0.0/performance/list_index_loop.bend as List_index_loop

performance/list_index_loop: a loop that reads a list from its head on each step. A definition passes a list parameter unchanged to a call of itself, and, in the same branch, gives it to List.get, List.drop, List.take, List.last or List.length, or to a definition of the file that gives its parameter to one of those. Heuristics: each of those walks the list from its head, so a loop of n steps over a list of n items takes O(n²) time, where walking the list takes O(n). A branch is the innermost case around the read; the loop's call must be in it too. It looks one definition deep, not further. A read in a type does not run, and is skipped. A read whose result is an argument of a call of the loop itself moves the loop along the list (a step, or a split in two: bend-ml's tensor-array fills a tree of bands so), and is not reported.

4 imports
import Base
import bend-lint-api@0.1.0.0/linter/lint.bend as Lint
import bend-lint-api@0.1.0.0/shared/lists.bend as Lists
import bend-lint-api@0.1.0.0/shared/names.bend as Names