[Lazarus] Mac (or other BigEndian machine) users needed to test new Utf8StringOfChar code

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue Sep 17 21:20:19 CEST 2013


Bart schrieb:
> On 9/17/13, Mark Morgan Lloyd <markMLl.lazarus at telemetry.co.uk> wrote:
>> Hans-Peter Diettrich wrote:
> 
> HPD code
>     3:
>     begin
>       Result := AUtf8Char;
>       SetLength(Result, nb);
>       PC := PChar(Result);
>       for i:=1 to nb - UCharLen do
>       begin
>         PC[UCharLen] := PC[0];  //very nice b.t.w.
>         inc(PC);
>       end;
>     end;
> 
> My code
> 
>     3:
>     begin
>       SetLength(Result, 3 * N);
>       C1 := AUtf8Char[1];
>       C2 := AUtf8Char[2];
>       C3 := AUtf8Char[3];
>       PC := PChar(Result);
>       for i:=1 to N do
>       begin
>         PC^ := C1; inc(PC);
>         PC^ := C2; inc(PC);
>         PC^ := C3; inc(PC);
>       end;
>     end;
> 
> I tested that for speed, and though they consistently differ about
> 2-6%, on further inspection this is dependant on the order the 2 are
> executed: the first one is always the slower...
> So, I conclude they perform roughly the same.

Thanks for testing :-)

Did you only test the 3-byte case, or also for WORD and DWORD cases? I 
left the "3:" only as a comment to the pattern taken from your code, 
while my version works for any length of the AUTF8Char, not only for the 
3-byte case. It's suited to allow for compiler optimizations, so that 
e.g. REP MOVSB or other streaming instructions could be used for the 
entire loop, as available for a target CPU. This feature makes the 
function usable even for replication of entire strings, of any encoding, 
when the parameter and result type is changed to RawByteString.

DoDi





More information about the Lazarus mailing list