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

Bart bartjunk64 at gmail.com
Tue Sep 17 18:04:05 CEST 2013


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.

Bart




More information about the Lazarus mailing list