From 3608f8df4a6a743e53a12286db9dc491fa9c5083 Mon Sep 17 00:00:00 2001 From: Juha Date: Sun, 29 Dec 2024 12:09:01 +0200 Subject: [PATCH] LazUtils: Optimize function UTF8StringReplace a little. (cherry picked from commit 277cc26bdc1eeccf941b453324b9911b45542b34) --- components/lazutils/lazutf8.pas | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/lazutils/lazutf8.pas b/components/lazutils/lazutf8.pas index 503926d89a..f96f22a8a0 100644 --- a/components/lazutils/lazutf8.pas +++ b/components/lazutils/lazutf8.pas @@ -1211,9 +1211,9 @@ end; function UTF8StringReplace(const S, OldPattern, NewPattern: String; Flags: TReplaceFlags; out Count: Integer; const ALanguage: string=''): String; var - SrcS, OldPtrn, TempS: string; + SrcS, OldPtrn: string; PSrc, POrig: PChar; - CharLen, OldPatLen: Integer; + CharLen, OldPatLen, l: Integer; OkToReplace: Boolean; begin Count := 0; @@ -1252,9 +1252,9 @@ begin Inc(PSrc, CharLen); // Next Codepoint // Copy a codepoint from original string and move forward CharLen := UTF8CodepointSize(POrig); - SetLength(TempS{%H-}, CharLen); - System.Move(POrig^, TempS[1], CharLen); - Result := Result + TempS; // Copy one codepoint from original string + l := Length(Result); + SetLength(Result, l+CharLen); // Copy one codepoint from original string + System.Move(POrig^, Result[l+1], CharLen); Inc(POrig, CharLen); // Next Codepoint end; end;