Browse Source

* optimize additions of empty sets away if possible, part of #40384

florian 1 year ago
parent
commit
e35403c3b8
1 changed files with 12 additions and 3 deletions
  1. 12 3
      compiler/nadd.pas

+ 12 - 3
compiler/nadd.pas

@@ -3597,6 +3597,7 @@ implementation
         temp    : ttempcreatenode;
         temp    : ttempcreatenode;
       begin
       begin
         result:=nil;
         result:=nil;
+
         case nodetype of
         case nodetype of
           equaln,unequaln,lten,gten:
           equaln,unequaln,lten,gten:
             begin
             begin
@@ -4302,9 +4303,6 @@ implementation
         end;
         end;
 
 
       var
       var
-{$ifdef addstringopt}
-         hp      : tnode;
-{$endif addstringopt}
          rd,ld   : tdef;
          rd,ld   : tdef;
          i,i2    : longint;
          i,i2    : longint;
          lt,rt   : tnodetype;
          lt,rt   : tnodetype;
@@ -4389,6 +4387,17 @@ implementation
                end;
                end;
            end;
            end;
 
 
+        { get rid of adding empty sets generated by set constructors (s+([]+[..]))
+
+          this needs to be done before firstpass, else the set additions get already converted into calls }
+        if (resultdef.typ=setdef) and (nodetype=addn) and (right.nodetype=addn) and (is_emptyset(taddnode(right).left)) then
+          begin
+            result:=caddnode.create(addn,left,taddnode(right).right);
+            left:=nil;
+            taddnode(right).right:=nil;
+            exit;
+          end;
+
          { first do the two subtrees }
          { first do the two subtrees }
          firstpass(left);
          firstpass(left);
          firstpass(right);
          firstpass(right);