[SOLVED] Improvement of function TCustomApplication.FindOptionIndex lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2024-02-20 13:11 packages/fcl-base/src/custapp.pp has 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 function TCustomApplication.FindOptionIndex(const S: String;  var Longopt: Boolean; StartAt : Integer = -1): Integer; Var  SO,O : String;  I,P : Integer; begin  If Not CaseSensitiveOptions then    SO:=UpperCase(S)  else    SO:=S;  Result:=-1;  I:=StartAt;  if (I=-1) then    I:=ParamCount;  While (Result=-1) and (I>0) do    begin    O:=Params[i];    // - must be seen as an option value    If (Length(O)>1) and (O[1]=FOptionChar) then      begin      Delete(O,1,1);      LongOpt:=(Length(O)>0) and (O[1]=FOptionChar);    If LongOpt then        begin        Delete(O,1,1);        P:=Pos('=',O);        If (P<>0) then          O:=Copy(O,1,P-1);      end;      If Not CaseSensitiveOptions then        O:=UpperCase(O);    If (O=SO) then        Result:=i;      end;    Dec(i);    end;end; 1/2 The following lines contain a useless condition 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     If (Length(O)>1) and (O[1]=FOptionChar) then      begin      Delete(O,1,1);      LongOpt:=(Length(O)>0) and (O[1]=FOptionChar);The condition (Length(O)>0) is always true because before deleting the first character using "Delete(O,1,1);" the length of variable O was at least 2(due to the "If (Length(O)>1)" condition). So, "LongOpt:=(Length(O)>0) and (O[1]=FOptionChar);" has been replaced with "LongOpt:=(O[1]=FOptionChar);". 2/2 After that, "If (P<>0) then O:=Copy(O,1,P-1);" has been replaced with "If (P<>0) then SetLength(O,P-1);". Here is a patch ---------------------------------------------------------------------- AlexTP · 2024-02-23 12:17 posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40663 . ---------------------------------------------------------------------- Thaddy · 2024-02-23 15:06 You know I like micro optimizations, but in this case (Assuming {$B-} state) it does not seem to matter in the generated assembler. Although your logic is correct.