[fpc-pascal] WideStringToUCS4String optimization

Alexey Tor. aaa5500 at ya.ru
Fri Oct 11 18:12:32 CEST 2019


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



More information about the fpc-pascal mailing list