[fpc-devel] Re: enumerators
Marco van de Voort
marcov at stack.nl
Sun Nov 14 13:10:46 CET 2010
In our previous episode, Thaddy said:
> > 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.
True, but the difference is that in the for..in case it is guaranteed, while
in the for ..to case the compiler devel must make sure that it is the
special case of uniform iteration.
A more grave reason though is that Delphi does not have low() and high() on
sets and a request to add it by me in 2006 was closed with their equivalent
of "won't fix".
So without for..in there is no comfortable way to iterate over a set in both
fpc and delphi.
More information about the fpc-devel