Back

PRF016

String-to-char compare via Copy

Object Pascal — Delphi & Free Pascal
Info
Performance

Copy(S, I, 1) allocates a temporary string when direct indexing S[I] is faster

Copy(S, I, 1) allocates a temporary string when direct indexing S[I] is faster.

Why this severity

Copy(S, I, 1) allocates a temporary string when direct indexing S[I] is faster.


Known false positives

none expected; single-character Copy is always replaceable with indexing.

Remediation example

if S[1] = 'A' then
  DoWork;
// instead of: if Copy(S, 1, 1) = 'A' then

Reconnecting… Connection lost. Reload