mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-08 11:26:01 +02:00
* TRTTIWriter.fields_write_rtti_data: refactoring. Since TAsmList allows random access, a separate loop iteration to count fields is redundant. Simply count the actually written fields, then insert result before field data.
git-svn-id: trunk@16611 -
This commit is contained in:
parent
ce93333bda
commit
b50cf9a42a
@ -36,7 +36,6 @@ interface
|
|||||||
|
|
||||||
TRTTIWriter=class
|
TRTTIWriter=class
|
||||||
private
|
private
|
||||||
function fields_count(st:tsymtable;rt:trttitype):longint;
|
|
||||||
procedure fields_write_rtti(st:tsymtable;rt:trttitype);
|
procedure fields_write_rtti(st:tsymtable;rt:trttitype);
|
||||||
procedure fields_write_rtti_data(st:tsymtable;rt:trttitype);
|
procedure fields_write_rtti_data(st:tsymtable;rt:trttitype);
|
||||||
procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
|
procedure write_rtti_extrasyms(def:Tdef;rt:Trttitype;mainrtti:Tasmsymbol);
|
||||||
@ -137,32 +136,21 @@ implementation
|
|||||||
current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0));
|
current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ writes a 32-bit count followed by array of field infos for given symtable }
|
||||||
function TRTTIWriter.fields_count(st:tsymtable;rt:trttitype):longint;
|
|
||||||
var
|
|
||||||
i : longint;
|
|
||||||
sym : tsym;
|
|
||||||
begin
|
|
||||||
result:=0;
|
|
||||||
for i:=0 to st.SymList.Count-1 do
|
|
||||||
begin
|
|
||||||
sym:=tsym(st.SymList[i]);
|
|
||||||
if (tsym(sym).typ=fieldvarsym) and
|
|
||||||
not(sp_static in tsym(sym).symoptions) and
|
|
||||||
(
|
|
||||||
(rt=fullrtti) or
|
|
||||||
tfieldvarsym(sym).vardef.needs_inittable
|
|
||||||
) then
|
|
||||||
inc(result);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TRTTIWriter.fields_write_rtti_data(st:tsymtable;rt:trttitype);
|
procedure TRTTIWriter.fields_write_rtti_data(st:tsymtable;rt:trttitype);
|
||||||
var
|
var
|
||||||
i : longint;
|
i : longint;
|
||||||
sym : tsym;
|
sym : tsym;
|
||||||
|
fieldcnt: longint;
|
||||||
|
lastai: TLinkedListItem;
|
||||||
begin
|
begin
|
||||||
|
fieldcnt:=0;
|
||||||
|
{ Count will be inserted at this location. It cannot be nil as we've just
|
||||||
|
written header for this symtable owner. But stay safe. }
|
||||||
|
lastai:=current_asmdata.asmlists[al_rtti].last;
|
||||||
|
if lastai=nil then
|
||||||
|
InternalError(201012212);
|
||||||
|
|
||||||
for i:=0 to st.SymList.Count-1 do
|
for i:=0 to st.SymList.Count-1 do
|
||||||
begin
|
begin
|
||||||
sym:=tsym(st.SymList[i]);
|
sym:=tsym(st.SymList[i]);
|
||||||
@ -175,8 +163,11 @@ implementation
|
|||||||
begin
|
begin
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tfieldvarsym(sym).vardef,rt)));
|
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(tfieldvarsym(sym).vardef,rt)));
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
|
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
|
||||||
|
inc(fieldcnt);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{ insert field count before data }
|
||||||
|
current_asmdata.asmlists[al_rtti].InsertAfter(Tai_const.Create_32bit(fieldcnt),lastai)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -609,14 +600,10 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure recorddef_rtti(def:trecorddef);
|
procedure recorddef_rtti(def:trecorddef);
|
||||||
var
|
|
||||||
fieldcnt : longint;
|
|
||||||
begin
|
begin
|
||||||
write_header(def,tkRecord);
|
write_header(def,tkRecord);
|
||||||
maybe_write_align;
|
maybe_write_align;
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
|
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
|
||||||
fieldcnt:=fields_count(def.symtable,rt);
|
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fieldcnt));
|
|
||||||
fields_write_rtti_data(def.symtable,rt);
|
fields_write_rtti_data(def.symtable,rt);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -750,7 +737,6 @@ implementation
|
|||||||
procedure objectdef_rtti_class_init(def:tobjectdef);
|
procedure objectdef_rtti_class_init(def:tobjectdef);
|
||||||
begin
|
begin
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
|
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(def.size));
|
||||||
current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(fields_count(def.symtable,rt)));
|
|
||||||
fields_write_rtti_data(def.symtable,rt);
|
fields_write_rtti_data(def.symtable,rt);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user