[fpc-devel] for-in-index loop

Michael Van Canneyt michael at freepascal.org
Fri Jan 25 11:27:28 CET 2013



On Fri, 25 Jan 2013, Michael Schnell wrote:

> On 01/25/2013 11:12 AM, Michael Van Canneyt wrote:
>> 
>> Pchar ?
>> 
> You seem to miss my point: the n'th printable character in an utf-8 coded 
> string (may same be stored as a pchar or a string) starts at the m'th byte 
> (m>=n).

I know that.

> To find m for a given n you need to scan all bytes < m.

I know that too.

> Thus a loop such as
>
> for I = 1 to 100000 do begin
>  n = Integer (random(100000));
>  c = myString[n];
> end;
>
> Is rather fast with ANSI coded Strings.

Yes, but this is random access in a string.

Enumerators will not help you with random access, only with sequential access.

Michael.



More information about the fpc-devel mailing list