[Optimization] Unreachable code with exit(result); expression
Original Reporter info from Mantis: Simon Ameis @SAmeis
-
Reporter name: Simon Ameis
Original Reporter info from Mantis: Simon Ameis @SAmeis
- Reporter name: Simon Ameis
Description:
The following code produces javascript code which is not optimal:
function TLoginPage.btnLogin_Click(Event: TJSMouseEvent): Boolean;
begin
if myvar = '' then
begin
exit(False);
end;
// do something else
exit(True);
end;
results in
this.btnLogin_Click = function (Event) {
var Result = false;
if (myvar === "") {
return false;
};
// do something else
return true;
return Result;
};
the variable Result is never used by user code and thus could be removed.
Also the return true; leads to unreachable code: return Result;
Additional information:
This could lead to performance issues if the function is called very often. Otherwise this is only a minor optimization.
Mantis conversion info:
- Mantis ID: 35860
- OS: Windows 7, 64 bit
- OS Build: 6.1 SP 1
- Build: trunk
- Platform: Desktop PC
- Monitored by: » @PascalDragon (Sven Barth)