performance/append_in_loop.bend fails
raw source on the hub · import bend-lint-rules@0.1.0.0/performance/append_in_loop.bend as Append_in_loop
performance/append_in_loop: a loop that appends to its accumulator. A definition passes
List.append(.., acc, ..) or acc ++ .. to a call of itself, where acc is one of its parameters.
Heuristics: an append copies acc, so a loop of n steps copies O(n²) items, where adding at the head
copies none. ++ copies only on the C lane: the JS lane joins strings natively. A loop that also
keeps each value it builds, by passing acc in another argument too, needs the copies: it is not
reported. It knows Base's List.append and String.append (++), not other functions that copy
their first argument.
3 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
The reader could not load this file (at 0x2b0a0dcada30f71a8eb4ec2e148b9279/linter/lint.bend:522). What bend.ts says:
Error:
- expected : a fresh constructor name (duplicate declaration: Text)
- observed : 'Text'
Location:
521 | Flag{on: Bool}
522>| Text{text: String}
| ^^^^
523 |