Back

PRF010

Sorting in loop

Object Pascal — Delphi & Free Pascal
Warning
Performance

Sorting inside a loop multiplies the cost dramatically; sort once after all mutations

sorting inside a loop multiplies the cost dramatically; sort once after all mutations.

Why this severity

sorting inside a loop multiplies the cost dramatically; sort once after all mutations.


Known false positives

loops that must maintain a sorted invariant between dependent operations.

Remediation example

for I := 0 to Count - 1 do
  List.Add(Items[I]);
List.Sort; // sort once after the loop

Reconnecting… Connection lost. Reload