Browse Source

Small optimization for the search of operator overloads. Add a flag "sto_has_generic" to all symtables that contain an operator overload (the flag propagates up the owning symtables) and check this flag when searching for units with operators.

symconst.pas:
  + add "sto_has_operator" to "tsymtableoption"
pdecsub.pas:
  + include the flag "sto_has_operator" for all operator declarations and their owning symtables
htypechk.pas, tcallcandidates:
  * create_candidate_list: only check for operator overloads if the record does indeed declare some
  * collect_overloads_in_units: only check for operator overloads if the unit does indeed declare some
utils/ppudump.pp:
  + respect the new "sto_has_operator" flag

git-svn-id: trunk@23688 -
svenbarth 12 years ago
parent
commit
168c9d152f
4 changed files with 15 additions and 5 deletions
  1. 8 2
      compiler/htypechk.pas
  2. 3 1
      compiler/pdecsub.pas
  3. 2 1
      compiler/symconst.pas
  4. 2 1
      compiler/utils/ppudump.pp

+ 8 - 2
compiler/htypechk.pas

@@ -2280,7 +2280,12 @@ implementation
                (FProcsymtable.symtabletype in [globalsymtable,staticsymtable]) and
                (srsymtable.moduleid<>FProcsymtable.moduleid) then
               break;
-            if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
+            if (srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable]) and
+                (
+                  (FOperator=NOTOKEN) or
+                  (sto_has_operator in srsymtable.tableoptions)
+                )
+               then
               begin
                 srsym:=tsym(srsymtable.FindWithHash(hashedid));
                 if assigned(srsym) and
@@ -2343,7 +2348,8 @@ implementation
             pt:=tcallparanode(FParaNode);
             while assigned(pt) do
               begin
-                if (pt.resultdef.typ=recorddef) then
+                if (pt.resultdef.typ=recorddef) and
+                    (sto_has_operator in tabstractrecorddef(pt.resultdef).owner.tableoptions) then
                   collect_overloads_in_struct(tabstractrecorddef(pt.resultdef),ProcdefOverloadList,searchhelpers,anoninherited);
                 pt:=tcallparanode(pt.right);
               end;

+ 3 - 1
compiler/pdecsub.pas

@@ -1221,8 +1221,10 @@ implementation
               block_type:=old_block_type;
               if assigned(pd) then
                 begin
-                  { operators always need to be searched in all units }
+                  { operators always need to be searched in all units (that
+                    contain operators) }
                   include(pd.procoptions,po_overload);
+                  pd.procsym.owner.includeoption(sto_has_operator);
                   if pd.parast.symtablelevel>normal_function_level then
                     Message(parser_e_no_local_operator);
                   if isclassmethod then

+ 2 - 1
compiler/symconst.pas

@@ -532,7 +532,8 @@ type
   { options for symtables }
   tsymtableoption = (
     sto_has_helper,       { contains at least one helper symbol }
-    sto_has_generic       { contains at least one generic symbol }
+    sto_has_generic,      { contains at least one generic symbol }
+    sto_has_operator      { contains at least one operator overload }
   );
   tsymtableoptions = set of tsymtableoption;
 

+ 2 - 1
compiler/utils/ppudump.pp

@@ -535,7 +535,8 @@ const
   symtblopts=ord(high(tsymtableoption))  + 1;
   symtblopt : array[1..symtblopts] of tsymtblopt=(
      (mask:sto_has_helper;   str:'Has helper'),
-     (mask:sto_has_generic;  str:'Has generic')
+     (mask:sto_has_generic;  str:'Has generic'),
+     (mask:sto_has_operator; str:'Has operator')
   );
 var
   options : tsymtableoptions;