Recent

Author Topic: [SOLVED] Improvement of rtl/objpas/sysutils/sysstr.inc function CompareStr  (Read 657 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
The function has a useless declaration of variable "res". Also useless is the initial "result := 0;" assignment.
Here is the content of the function.
Code: Pascal  [Select][+][-]
  1. function CompareStr(const S1, S2: string): Integer;
  2. var res,count, count1, count2: SizeInt;
  3. begin
  4.   result := 0;
  5.   Count1 := Length(S1);
  6.   Count2 := Length(S2);
  7.   if Count1>Count2 then
  8.     Count:=Count2
  9.   else
  10.     Count:=Count1;
  11.   result := CompareMemRange(Pointer(S1),Pointer(S2), Count);
  12.   if result=0 then
  13.     // CAPSIZEINT is no-op if Sizeof(Sizeint)<=SizeOF(Integer)
  14.     result:=CAPSIZEINT(Count1-Count2);
  15. end;
« Last Edit: April 11, 2023, 04:35:00 pm by lagprogramming »

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
Re: Improvement of rtl/objpas/sysutils/sysstr.inc function CompareStr
« Reply #1 on: April 09, 2023, 04:08:31 pm »
Here is a patch
Code: Pascal  [Select][+][-]
  1. diff --git a/rtl/objpas/sysutils/sysstr.inc b/rtl/objpas/sysutils/sysstr.inc
  2. index 318ef2c03c..ee45222d2f 100644
  3. --- a/rtl/objpas/sysutils/sysstr.inc
  4. +++ b/rtl/objpas/sysutils/sysstr.inc
  5. @@ -181,9 +181,8 @@ function LowerCase(const V: variant): string; overload;{$ifdef SYSUTILSINLINE}in
  6.  {$ENDIF}
  7.  
  8.  function CompareStr(const S1, S2: string): Integer;
  9. -var res,count, count1, count2: SizeInt;
  10. +var count, count1, count2: SizeInt;
  11.  begin
  12. -  result := 0;
  13.    Count1 := Length(S1);
  14.    Count2 := Length(S2);
  15.    if Count1>Count2 then

 

TinyPortal © 2005-2018