From 168c9d152f175566c612e2ec5efe925d9c7acd12 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Mon, 4 Mar 2013 16:02:18 +0000 Subject: [PATCH] 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 - --- compiler/htypechk.pas | 10 ++++++++-- compiler/pdecsub.pas | 4 +++- compiler/symconst.pas | 3 ++- compiler/utils/ppudump.pp | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 284dd46d39..ec2e286953 100644 --- a/compiler/htypechk.pas +++ b/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; diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index 0ba87dcb4f..0e12f5f611 100644 --- a/compiler/pdecsub.pas +++ b/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 diff --git a/compiler/symconst.pas b/compiler/symconst.pas index 8d0000b15f..22829e234a 100644 --- a/compiler/symconst.pas +++ b/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; diff --git a/compiler/utils/ppudump.pp b/compiler/utils/ppudump.pp index 9292ed1674..98710523f4 100644 --- a/compiler/utils/ppudump.pp +++ b/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;