I don’t know the compiler for sure on this, but surely has to be that the set
option gets compiled like a case statement, which minimises the number of
comparisons made.
Speaking of which, I just this week combined this with a case statement – not
clearly documented but it does work. This example is sanitising an ansi/ascii
file for non-printing characters
case FileBytes[i] of
10,13: begin
//handle end of line
end;
9,12,32..126:
begin
//handle printable characters (9=tab, 12=page break)
end
else
begin
//handle everything else not printable
end;
end;
(This was to overcome the TStringlist.loadfromfile limitation where large files
or files with any binary zeros only partially load.)
From: Ross Levis
Sent: Wednesday, June 8, 2016 4:56 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] In [set] efficiency
I’m wondering which is more efficient to process...
if (a=1) or (a=2) then ...
or
if a in [1,2] then ...
If the answer is the first method, does it make a difference if more numbers
are checked, eg. if a in [1..3,5] then
Cheers.
--------------------------------------------------------------------------------
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [email protected] with
Subject: unsubscribe_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [email protected] with
Subject: unsubscribe