rtl/objpas/sysutils/fina.inc has the folowing routines:
function ChangeFileExt(const FileName, Extension: PathStr): PathStr;
function ExtractFilePath(const FileName: PathStr): PathStr;
function ExtractFileDir(const FileName: PathStr): PathStr;
function ExtractFileName(const FileName: PathStr): PathStr;
function ExtractFileExt(const FileName:PathStr):PathStr;
Switching the "I" and "EndSep" assignment lines makes the compiler produce better code. You can verify by looking at the generated assembly file.
I'm talking about the lines like:
I := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
The following patch modifies all the above functions.
diff --git a/rtl/objpas/sysutils/fina.inc b/rtl/objpas/sysutils/fina.inc
index e817d60e6a..95217a026b 100644
--- a/rtl/objpas/sysutils/fina.inc
+++ b/rtl/objpas/sysutils/fina.inc
@@ -21,8 +21,8 @@ function ChangeFileExt(const FileName, Extension: PathStr): PathStr;
SOF : Boolean;
begin
- i := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators+[ExtensionSeparator];
+ i := Length(FileName);
while (I > 0) and not(FileName[I] in EndSep) do
Dec(I);
if (I = 0) or (FileName[I] <> ExtensionSeparator) then
@@ -41,8 +41,8 @@ function ExtractFilePath(const FileName: PathStr): PathStr;
i : longint;
EndSep : Set of Char;
begin
- i := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
+ i := Length(FileName);
while (i > 0) and not CharInSet(FileName[i],EndSep) do
Dec(i);
If I>0 then
@@ -56,8 +56,8 @@ function ExtractFileDir(const FileName: PathStr): PathStr;
i : longint;
EndSep : Set of Char;
begin
- I := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
+ I := Length(FileName);
while (I > 0) and not CharInSet(FileName[I],EndSep) do
Dec(I);
if (I > 1) and CharInSet(FileName[I],AllowDirectorySeparators) and
@@ -102,8 +102,8 @@ function ExtractFileName(const FileName: PathStr): PathStr;
i : longint;
EndSep : Set of Char;
begin
- I := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
+ I := Length(FileName);
while (I > 0) and not CharInSet(FileName[I],EndSep) do
Dec(I);
Result := Copy(FileName, I + 1, MaxInt);
@@ -117,8 +117,8 @@ function ExtractFileExt(const FileName: PathStr): PathStr;
begin
Result:='';
- I := Length(FileName);
EndSep:=AllowDirectorySeparators+AllowDriveSeparators+[ExtensionSeparator];
+ I := Length(FileName);
while (I > 0) and not CharInSet(FileName[I],EndSep) do
Dec(I);
if (I > 0) and (FileName[I] = ExtensionSeparator) then