Explorar o código

* optimize case statements with a single branch into if statements (ord const only)

git-svn-id: trunk@43766 -
florian %!s(int64=5) %!d(string=hai) anos
pai
achega
abb79553d2
Modificáronse 1 ficheiros con 24 adicións e 1 borrados
  1. 24 1
      compiler/nset.pas

+ 24 - 1
compiler/nset.pas

@@ -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;