[Lazarus] Optimize SwapEndian for widestring?

Michael Van Canneyt michael at freepascal.org
Tue Aug 1 16:15:05 CEST 2017



On Tue, 1 Aug 2017, Alexey via Lazarus wrote:

> Pls tell can I optimize this func? E.g. calc each char's PWord and 
> read/write word.
>
>

Probably this will be faster:

  function SSwapEndian(const S: UnicodeString): UnicodeString;
  var
    i: integer;
    p :pwidechar;
  begin
    Result:= S;
    UniqueString(Result);
    P:=PWideChar(Result[1]));
    for i:= 1 to Length(Result) do
      begin
      P^:= WideChar(SwapEndian(P^));
      Inc(P);
      end;
  end;


More information about the Lazarus mailing list