packages/fcl-base/src/custapp.pp has the following procedure:
Procedure SysGetEnvironmentList(List : TStrings;NamesOnly : Boolean);
var
s : string;
i,l,j,count : longint;
begin
count:=GetEnvironmentVariableCount;
if count>0 then
for j:=1 to count do
begin
s:=GetEnvironmentString(j);
l:=Length(s);
If NamesOnly then
begin
I:=pos('=',s);
If (I>0) then
S:=Copy(S,1,I-1);
end;
List.Add(S);
end;
end;
Variable
l is declared and a value is assigned to it but it's never used.
Also, the line
if count>0 then adds an unnecessary conditional jump. Either it remains and the for loop is replaced with a repeat loop, either the if statement is removed.
1/2 The following patch removes the
l variable declaration, the
l:=Length(s); line and the
if count>0 then line.
diff --git a/packages/fcl-base/src/custapp.pp b/packages/fcl-base/src/custapp.pp
index adb0ff46ae..c6a4b064b8 100644
--- a/packages/fcl-base/src/custapp.pp
+++ b/packages/fcl-base/src/custapp.pp
@@ -176,22 +176,20 @@ function TCustomApplication.GetExeName: string;
var
s : string;
- i,l,j,count : longint;
+ i,j,count : longint;
begin
count:=GetEnvironmentVariableCount;
- if count>0 then
- for j:=1 to count do
- begin
- s:=GetEnvironmentString(j);
- l:=Length(s);
- If NamesOnly then
- begin
- I:=pos('=',s);
- If (I>0) then
- S:=Copy(S,1,I-1);
- end;
- List.Add(S);
+ for j:=1 to count do
+ begin
+ s:=GetEnvironmentString(j);
+ If NamesOnly then
+ begin
+ I:=pos('=',s);
+ If (I>0) then
+ S:=Copy(S,1,I-1);
+ end;
+ List.Add(S);
end;
end;
2/2 One last thing. Unlike the SysGetEnvironmentList functions in packages/fcl-base/src/go32v2/custapp.inc and packages/fcl-base/src/os2/custapp.inc which contain the code
If (I>1) then S:=Copy(S,1,I-1);the SysGetEnvironmentList function in fcl-base/src/custapp.pp contains the code
If (I>0) then S:=Copy(S,1,I-1);I was thinking that maybe they should look alike, I mean compare
I with the same value.