[SOLVED] Optimization of function ParseURI lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-08-06 07:55 packages/fcl-base/src/uriparser.pp has function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode : Boolean = True):  TURI; The following patch replaces: s := Copy(s, 1, i - 1); with SetLength(s, i - 1); s := Copy(s, 1, i) with SetLength(s, i) Authority := Copy(Authority, 1, i - 1); with SetLength(Authority, i - 1); Delete(Authority, i, MaxInt); with SetLength(Authority, i - 1); if Length(Authority) > 0 then with if Authority <> '' then In addition, some spaces have been added to Result.Host := Copy(Authority, i+1, MaxInt); Here is the patch: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i diff --git a/packages/fcl-base/src/uriparser.pp b/packages/fcl- base/src/uriparser.ppindex 10ffc90ad8..58d07e28df 100644--- a/packages/fcl-base/src/uriparser.pp+++ b/packages/fcl- base/src/uriparser.pp@@ -207,7 +207,7 @@ function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode :     Result.Bookmark := Copy(s, i + 1, MaxInt);     if Decode then       Result.Bookmark:=Unescape(Result.Bookmark);-    s := Copy(s, 1, i - 1);+    SetLength(s, i - 1);   end;    // Extract the params@@ -218,7 +218,7 @@ function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode :     Result.Params := Copy(s, i + 1, MaxInt);     if Decode then       Result.Params:=Unescape(Result.Params);-    s := Copy(s, 1, i - 1);+  SetLength(s, i - 1);   end;    // extract authority@@ -248,7 +248,7 @@ function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode :       if Decode then         Result.Document:=Unescape(Result.Document);       if (Result.Document <> '.') and (Result.Document <> '..') then-        s := Copy(s, 1, i)+        SetLength(s, i)       else         Result.Document := '';       break;@@ -287,7 +287,7 @@ function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode :     if PortValid then     begin       Result.Port := StrToInt(Copy(Authority, i + 1, MaxInt));-      Authority := Copy(Authority, 1, i - 1);+      SetLength(Authority, i - 1);     end;   end; @@ -296,11 +296,11 @@ function ParseURI(const URI, DefaultProtocol: String; DefaultPort: Word;Decode :   i := Pos('@', Authority);   if i > 0 then   begin-    Result.Host := Copy(Authority, i+1, MaxInt);-    Delete(Authority, i, MaxInt);+    Result.Host := Copy(Authority, i + 1, MaxInt);+    SetLength(Authority, i - 1);      // Extract username and password-  if Length(Authority) > 0 then+    if Authority <> '' then     begin     i := Pos(':', Authority);       if i = 0 then ---------------------------------------------------------------------- AlexTP · 2023-08-06 08:35 Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40378