mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 06:29:32 +02:00
* optimize case statements with a single branch into if statements (ord const only)
git-svn-id: trunk@43766 -
This commit is contained in:
parent
cb44d7d4e2
commit
abb79553d2
@ -919,8 +919,31 @@ implementation
|
||||
end;
|
||||
result:=cifnode.create(left,node_thenblock,node_elseblock);
|
||||
left:=nil;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
{ convert single case branch into if-statement }
|
||||
if (flabels^.greater=nil) and (flabels^.less=nil) then
|
||||
if flabels^.label_type=ltOrdinal then
|
||||
begin
|
||||
if flabels^._low=flabels^._high then
|
||||
begin
|
||||
result:=cifnode.create_internal(
|
||||
caddnode.create_internal(equaln,left.getcopy,cordconstnode.create(flabels^._low,left.resultdef,false)),
|
||||
pcaseblock(blocks[flabels^.blockid])^.statement.getcopy,elseblock);
|
||||
end
|
||||
else
|
||||
begin
|
||||
result:=cifnode.create_internal(
|
||||
caddnode.create_internal(andn,
|
||||
caddnode.create_internal(gten,left.getcopy,cordconstnode.create(flabels^._low,left.resultdef,false)),
|
||||
caddnode.create_internal(lten,left.getcopy,cordconstnode.create(flabels^._high,left.resultdef,false))
|
||||
),
|
||||
pcaseblock(blocks[flabels^.blockid])^.statement.getcopy,elseblock);
|
||||
end;
|
||||
elseblock:=nil;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function tcasenode.simplify(forinline:boolean):tnode;
|
||||
|
Loading…
Reference in New Issue
Block a user