Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-10

WideStringToUCS4String optimization

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexey Tor.

Hi

{$ifdef FPC_HAS_FEATURE_DYNARRAYS}
procedure UCS4Encode(p: PWideChar; len: sizeint; out res: UCS4String);
   var
     i, reslen: sizeint;
     w: longint;
   begin
     reslen:=0;
     i:=0;
     { calculate required length }

this func loops over the buffer 2 times. 1) find len in UCS4 chars, 2) make UCS4 contents. Maybe make one loop only? Ie- a) SetLength for result to the len of source. b) single loop: copy content and also calculate real len. c) adjust (decrease) result len, if surrogate pairs were found (N pairs -> decrease by N)

Regards, Alexey