[fpc-devel] Re: enumerators

Thaddy thaddy at thaddy.com
Sun Nov 14 09:11:25 CET 2010

On 13-11-2010 20:56, Hans-Peter Diettrich wrote:
> The comparison in the UTF-8 string example is very questionable. First 
> ch(i) is not equivalent to ch, not even closely related, and the claim 
> of O(N^2) operations deserves an proof - IMO it's simply wrong.
Yes, this caught my eye as well: O(N^2) seems only the case if "length" 
would be evaluated every time. Since you should not modify the index 
(although this is possible with some tricks in Delphi) the compiler 
should optimize it away.
If you look at the algorithm, however, the statement is correct: it 
implies/reads: "evaluate length every iteration", whereas "for..in" 
evaluates the index value only once.

More information about the fpc-devel mailing list