[DUG] In [set] efficiency
John Bird
johnkbird at paradise.net.nz
Wed Jun 8 17:26:44 NZST 2016
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: delphi at listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at listserver.123.net.nz with Subject: unsubscribe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20160608/5277e2fd/attachment.html
More information about the Delphi
mailing list