From 9caabdc4e78ea95eba77a4ac9e17be420fbf4188 Mon Sep 17 00:00:00 2001 From: Alligator-1 Date: Mon, 8 Jul 2024 21:33:31 +0500 Subject: [PATCH] Immediately set the capacity --- compiler/fppu.pas | 2 ++ compiler/ncal.pas | 1 + compiler/ogbase.pas | 1 + compiler/ogelf.pas | 2 ++ compiler/pgentype.pas | 2 ++ compiler/pgenutil.pas | 3 +++ compiler/procdefutil.pas | 1 + compiler/symdef.pas | 4 ++++ compiler/symsym.pas | 17 +++++++++++------ compiler/symtable.pas | 1 + 10 files changed, 28 insertions(+), 6 deletions(-) diff --git a/compiler/fppu.pas b/compiler/fppu.pas index e3d432f75e..ab761bd269 100644 --- a/compiler/fppu.pas +++ b/compiler/fppu.pas @@ -791,6 +791,7 @@ var i : longint; deref : pderef; begin + unitimportsymsderefs.capacity:=unitimportsymsderefs.count+unitimportsyms.count; for i:=0 to unitimportsyms.count-1 do begin new(deref); @@ -805,6 +806,7 @@ var i : longint; sym : tsym; begin + unitimportsyms.capacity:=unitimportsyms.count+unitimportsymsderefs.count; for i:=0 to unitimportsymsderefs.count-1 do begin sym:=tsym(pderef(unitimportsymsderefs[i])^.resolve); diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 36a9ed98d0..0784d85400 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -1867,6 +1867,7 @@ implementation if assigned(varargsparas) then begin n.varargsparas:=tvarargsparalist.create(true); + n.varargsparas.capacity:=varargsparas.count; for i:=0 to varargsparas.count-1 do begin hp:=tparavarsym(varargsparas[i]); diff --git a/compiler/ogbase.pas b/compiler/ogbase.pas index e0e07bb1f3..ebe37ff8ee 100644 --- a/compiler/ogbase.pas +++ b/compiler/ogbase.pas @@ -3326,6 +3326,7 @@ implementation exit; { create a list of symbols sorted by address } list:=TFPList.Create; + list.Capacity:=ExeSymbolList.Count; for i:=0 to ExeSymbolList.Count-1 do list.Add(TExeSymbol(ExeSymbolList[i]).ObjSymbol); list.Sort(@ByAddress); diff --git a/compiler/ogelf.pas b/compiler/ogelf.pas index 91b2ad9486..38f631e254 100644 --- a/compiler/ogelf.pas +++ b/compiler/ogelf.pas @@ -2271,6 +2271,7 @@ implementation newsections:=TFPHashObjectList.Create(false); allsections:=TFPList.Create; { copy existing sections } + allsections.Capacity:=ExeSectionList.Count; for i:=0 to ExeSectionList.Count-1 do allsections.add(ExeSectionList[i]); inserts[0]:=FindExeSection('.comment'); @@ -2688,6 +2689,7 @@ implementation if assigned(dynrelocsec) then begin { Append R_xx_COPY relocations } + dynreloclist.capacity:=dynreloclist.count+dyncopysyms.count; for i:=0 to dyncopysyms.count-1 do begin objsym:=TObjSymbol(dyncopysyms[i]); diff --git a/compiler/pgentype.pas b/compiler/pgentype.pas index e91acca737..6deadd23fa 100644 --- a/compiler/pgentype.pas +++ b/compiler/pgentype.pas @@ -81,10 +81,12 @@ var i : longint; begin result:=tspecializationcontext.create; + result.paramlist.capacity:=paramlist.count; for i:=0 to paramlist.count-1 do begin result.paramlist.add(paramlist[i]); end; + result.poslist.capacity:=poslist.count; for i:=0 to poslist.count-1 do begin new(posinfo); diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index c117a9f622..5d22bac575 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -728,6 +728,8 @@ uses tmpparampos:=current_filepos; if genericparams.count<>genericdef.genericparas.count then internalerror(2021020901); + poslist.capacity:=poslist.count+genericparams.count; + context.paramlist.capacity:=context.paramlist.count+genericparams.count; for i:=0 to genericparams.count-1 do begin paramname:=generic_param_hash(ttypesym(genericdef.genericparas[i]).typedef); @@ -2961,6 +2963,7 @@ uses { add those defs back to the pending list for which we don't yet have all method bodies } + current_module.pendingspecializations.capacity:=current_module.pendingspecializations.count+readdlist.count; for i:=0 to readdlist.count-1 do current_module.pendingspecializations.add(tstoreddef(readdlist[i]).typename,readdlist[i]); diff --git a/compiler/procdefutil.pas b/compiler/procdefutil.pas index ee086aaab5..78e5184fa5 100644 --- a/compiler/procdefutil.pas +++ b/compiler/procdefutil.pas @@ -1698,6 +1698,7 @@ implementation tocapture.add(sym); end; + convertarg.mappings.capacity:=convertarg.mappings.count+tocapture.count; for i:=0 to tocapture.count-1 do begin new(mapping); diff --git a/compiler/symdef.pas b/compiler/symdef.pas index aac12462b3..f2b579ca19 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -2014,6 +2014,7 @@ implementation intfderef : pderef; i : longint; begin + interfacesderef.capacity:=interfacesderef.count+interfaces.count; for i:=0 to interfaces.count-1 do begin new(intfderef); @@ -2026,6 +2027,7 @@ implementation var i : longint; begin + interfaces.capacity:=interfaces.count+interfacesderef.count; for i:=0 to interfacesderef.count-1 do interfaces.add(pderef(interfacesderef[i])^.resolve); end; @@ -2411,6 +2413,7 @@ implementation begin if not assigned(genericparaderefs) then genericparaderefs:=tfplist.create; + genericparaderefs.capacity:=genericparaderefs.count+genericparas.count; for i:=0 to genericparas.count-1 do begin sym:=tsym(genericparas.items[i]); @@ -8084,6 +8087,7 @@ implementation tobjectdef(result).abstractcnt:=abstractcnt; if assigned(ImplementedInterfaces) then begin + tobjectdef(result).ImplementedInterfaces.capacity:=tobjectdef(result).ImplementedInterfaces.count+ImplementedInterfaces.count; for i:=0 to ImplementedInterfaces.count-1 do tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy); end; diff --git a/compiler/symsym.pas b/compiler/symsym.pas index d1d76d3dda..ca9f8a8c72 100644 --- a/compiler/symsym.pas +++ b/compiler/symsym.pas @@ -1081,12 +1081,15 @@ implementation { this might happen for procsyms in classes that override symbols in a parent class that generic overloads } if assigned(fgenprocsymovlds) then - for i:=0 to fgenprocsymovlds.count-1 do - begin - sym:=tprocsym(fgenprocsymovlds[i]); - d.build(sym); - fgenprocsymovldsderefs.add(pointer(ptrint(d.dataidx))); - end; + begin + fgenprocsymovldsderefs.capacity:=fgenprocsymovldsderefs.count+fgenprocsymovlds.count; + for i:=0 to fgenprocsymovlds.count-1 do + begin + sym:=tprocsym(fgenprocsymovlds[i]); + d.build(sym); + fgenprocsymovldsderefs.add(pointer(ptrint(d.dataidx))); + end; + end; end; end; @@ -1102,6 +1105,7 @@ implementation ProcdefList.Clear; if not assigned(FProcdefDerefList) then internalerror(200611031); + ProcdefList.capacity:=FProcdefDerefList.count; for i:=0 to FProcdefDerefList.Count-1 do begin d.dataidx:=PtrInt(FProcdefDerefList[i]); @@ -1117,6 +1121,7 @@ implementation if assigned(fgenprocsymovlds) then begin fgenprocsymovlds.clear; + fgenprocsymovlds.capacity:=fgenprocsymovldsderefs.count; for i:= 0 to fgenprocsymovldsderefs.count-1 do begin d.dataidx:=ptrint(fgenprocsymovldsderefs[i]); diff --git a/compiler/symtable.pas b/compiler/symtable.pas index b723b04ac9..edd576386d 100644 --- a/compiler/symtable.pas +++ b/compiler/symtable.pas @@ -1784,6 +1784,7 @@ implementation sublist:=tfplist.create; tabstractrecordsymtable(tabstractrecorddef(fsym.vardef).symtable).get_managementoperator_offset_list(mop,sublist); + mop_list[mop].capacity:=mop_list[mop].count+sublist.count; for i:=0 to sublist.count-1 do begin entry:=pmanagementoperator_offset_entry(sublist[i]);