* memory optimization with tconstsym (1.5%)

This commit is contained in:
carl 2002-11-22 22:48:10 +00:00
parent e15d019b58
commit 05d86bbef8
7 changed files with 126 additions and 110 deletions

View File

@ -307,16 +307,16 @@ implementation
constbool, constbool,
constchar, constchar,
constord : constord :
equal_constsym:=(sym1.valueord=sym2.valueord); equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
constpointer : constpointer :
equal_constsym:=(sym1.valueordptr=sym2.valueordptr); equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
conststring,constresourcestring : conststring,constresourcestring :
begin begin
if sym1.len=sym2.len then if sym1.value.len=sym2.value.len then
begin begin
p1:=pchar(sym1.valueptr); p1:=pchar(sym1.value.valueptr);
p2:=pchar(sym2.valueptr); p2:=pchar(sym2.value.valueptr);
pend:=p1+sym1.len; pend:=p1+sym1.value.len;
while (p1<pend) do while (p1<pend) do
begin begin
if p1^<>p2^ then if p1^<>p2^ then
@ -329,9 +329,9 @@ implementation
end; end;
end; end;
constreal : constreal :
equal_constsym:=(pbestreal(sym1.valueptr)^=pbestreal(sym2.valueptr)^); equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
constset : constset :
equal_constsym:=(pnormalset(sym1.valueptr)^=pnormalset(sym2.valueptr)^); equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
constnil : constnil :
equal_constsym:=true; equal_constsym:=true;
end; end;
@ -2040,7 +2040,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.26 2002-11-17 16:31:55 carl Revision 1.27 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.26 2002/11/17 16:31:55 carl
* memory optimization (3-4%) : cleanup of tai fields, * memory optimization (3-4%) : cleanup of tai fields,
cleanup of tdef and tsym fields. cleanup of tdef and tsym fields.
* make it work for m68k * make it work for m68k

View File

@ -305,29 +305,29 @@ implementation
p1:=nil; p1:=nil;
case p.consttyp of case p.consttyp of
constint : constint :
p1:=genintconstnode(p.valueord); p1:=genintconstnode(p.value.valueord);
conststring : conststring :
begin begin
len:=p.len; len:=p.value.len;
if not(cs_ansistrings in aktlocalswitches) and (len>255) then if not(cs_ansistrings in aktlocalswitches) and (len>255) then
len:=255; len:=255;
getmem(pc,len+1); getmem(pc,len+1);
move(pchar(p.valueptr)^,pc^,len); move(pchar(p.value.valueptr)^,pc^,len);
pc[len]:=#0; pc[len]:=#0;
p1:=cstringconstnode.createpchar(pc,len); p1:=cstringconstnode.createpchar(pc,len);
end; end;
constchar : constchar :
p1:=cordconstnode.create(p.valueord,cchartype,true); p1:=cordconstnode.create(p.value.valueord,cchartype,true);
constreal : constreal :
p1:=crealconstnode.create(pbestreal(p.valueptr)^,pbestrealtype^); p1:=crealconstnode.create(pbestreal(p.value.valueptr)^,pbestrealtype^);
constbool : constbool :
p1:=cordconstnode.create(p.valueord,booltype,true); p1:=cordconstnode.create(p.value.valueord,booltype,true);
constset : constset :
p1:=csetconstnode.create(pconstset(p.valueptr),p.consttype); p1:=csetconstnode.create(pconstset(p.value.valueptr),p.consttype);
constord : constord :
p1:=cordconstnode.create(p.valueord,p.consttype,true); p1:=cordconstnode.create(p.value.valueord,p.consttype,true);
constpointer : constpointer :
p1:=cpointerconstnode.create(p.valueordptr,p.consttype); p1:=cpointerconstnode.create(p.value.valueordptr,p.consttype);
constnil : constnil :
p1:=cnilnode.create; p1:=cnilnode.create;
else else
@ -924,7 +924,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.43 2002-10-05 12:43:25 carl Revision 1.44 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.43 2002/10/05 12:43:25 carl
* fixes for Delphi 6 compilation * fixes for Delphi 6 compilation
(warning : Some features do not work under Delphi) (warning : Some features do not work under Delphi)

View File

@ -1188,37 +1188,37 @@ implementation
constint : constint :
begin begin
{ do a very dirty trick to bootstrap this code } { do a very dirty trick to bootstrap this code }
if (tconstsym(srsym).valueord>=-(int64(2147483647)+int64(1))) and if (tconstsym(srsym).value.valueord>=-(int64(2147483647)+int64(1))) and
(tconstsym(srsym).valueord<=2147483647) then (tconstsym(srsym).value.valueord<=2147483647) then
p1:=cordconstnode.create(tconstsym(srsym).valueord,s32bittype,true) p1:=cordconstnode.create(tconstsym(srsym).value.valueord,s32bittype,true)
else if (tconstsym(srsym).valueord > maxlongint) and else if (tconstsym(srsym).value.valueord > maxlongint) and
(tconstsym(srsym).valueord <= int64(maxlongint)+int64(maxlongint)+1) then (tconstsym(srsym).value.valueord <= int64(maxlongint)+int64(maxlongint)+1) then
p1:=cordconstnode.create(tconstsym(srsym).valueord,u32bittype,true) p1:=cordconstnode.create(tconstsym(srsym).value.valueord,u32bittype,true)
else else
p1:=cordconstnode.create(tconstsym(srsym).valueord,cs64bittype,true); p1:=cordconstnode.create(tconstsym(srsym).value.valueord,cs64bittype,true);
end; end;
conststring : conststring :
begin begin
len:=tconstsym(srsym).len; len:=tconstsym(srsym).value.len;
if not(cs_ansistrings in aktlocalswitches) and (len>255) then if not(cs_ansistrings in aktlocalswitches) and (len>255) then
len:=255; len:=255;
getmem(pc,len+1); getmem(pc,len+1);
move(pchar(tconstsym(srsym).valueptr)^,pc^,len); move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
pc[len]:=#0; pc[len]:=#0;
p1:=cstringconstnode.createpchar(pc,len); p1:=cstringconstnode.createpchar(pc,len);
end; end;
constchar : constchar :
p1:=cordconstnode.create(tconstsym(srsym).valueord,cchartype,true); p1:=cordconstnode.create(tconstsym(srsym).value.valueord,cchartype,true);
constreal : constreal :
p1:=crealconstnode.create(pbestreal(tconstsym(srsym).valueptr)^,pbestrealtype^); p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
constbool : constbool :
p1:=cordconstnode.create(tconstsym(srsym).valueord,booltype,true); p1:=cordconstnode.create(tconstsym(srsym).value.valueord,booltype,true);
constset : constset :
p1:=csetconstnode.create(pconstset(tconstsym(srsym).valueptr),tconstsym(srsym).consttype); p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
constord : constord :
p1:=cordconstnode.create(tconstsym(srsym).valueord,tconstsym(srsym).consttype,true); p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
constpointer : constpointer :
p1:=cpointerconstnode.create(tconstsym(srsym).valueordptr,tconstsym(srsym).consttype); p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
constnil : constnil :
p1:=cnilnode.create; p1:=cnilnode.create;
constresourcestring: constresourcestring:
@ -1228,7 +1228,7 @@ implementation
p1.resulttype:=cansistringtype; p1.resulttype:=cansistringtype;
end; end;
constguid : constguid :
p1:=cguidconstnode.create(pguid(tconstsym(srsym).valueptr)^); p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
end; end;
end; end;
@ -2266,7 +2266,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.90 2002-11-20 22:49:55 pierre Revision 1.91 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.90 2002/11/20 22:49:55 pierre
* commented check code tht was invalid in 1.1 * commented check code tht was invalid in 1.1
Revision 1.89 2002/11/18 18:34:41 peter Revision 1.89 2002/11/18 18:34:41 peter

View File

@ -515,8 +515,8 @@ implementation
end end
else if is_constresourcestringnode(p) then else if is_constresourcestringnode(p) then
begin begin
strval:=pchar(tconstsym(tloadnode(p).symtableentry).valueptr); strval:=pchar(tconstsym(tloadnode(p).symtableentry).value.valueptr);
strlength:=tconstsym(tloadnode(p).symtableentry).len; strlength:=tconstsym(tloadnode(p).symtableentry).value.len;
end end
else else
begin begin
@ -985,7 +985,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.58 2002-11-09 15:31:57 carl Revision 1.59 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.58 2002/11/09 15:31:57 carl
+ align ansi/wide string constants + align ansi/wide string constants
Revision 1.57 2002/09/06 19:58:31 carl Revision 1.57 2002/09/06 19:58:31 carl

View File

@ -968,7 +968,7 @@ Begin
if tconstsym(sym).consttyp in [constint,constchar,constbool] then if tconstsym(sym).consttyp in [constint,constchar,constbool] then
begin begin
opr.typ:=OPR_CONSTANT; opr.typ:=OPR_CONSTANT;
opr.val:=tconstsym(sym).valueord; opr.val:=tconstsym(sym).value.valueord;
SetupVar:=true; SetupVar:=true;
Exit; Exit;
end; end;
@ -1278,7 +1278,7 @@ Begin
begin begin
if (tconstsym(srsym).consttyp in [constord,constint,constchar,constbool]) then if (tconstsym(srsym).consttyp in [constord,constint,constchar,constbool]) then
Begin Begin
l:=tconstsym(srsym).valueord; l:=tconstsym(srsym).value.valueord;
SearchIConstant:=TRUE; SearchIConstant:=TRUE;
exit; exit;
end; end;
@ -1592,7 +1592,10 @@ end;
end. end.
{ {
$Log$ $Log$
Revision 1.48 2002-11-18 17:31:59 peter Revision 1.49 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.48 2002/11/18 17:31:59 peter
* pass proccalloption to ret_in_xxx and push_xxx functions * pass proccalloption to ret_in_xxx and push_xxx functions
Revision 1.47 2002/11/15 16:29:31 peter Revision 1.47 2002/11/15 16:29:31 peter

View File

@ -3227,16 +3227,16 @@ implementation
case hpc.consttyp of case hpc.consttyp of
conststring, conststring,
constresourcestring : constresourcestring :
hs:=strpas(pchar(hpc.valueptr)); hs:=strpas(pchar(hpc.value.valueptr));
constreal : constreal :
str(pbestreal(hpc.valueptr)^,hs); str(pbestreal(hpc.value.valueptr)^,hs);
constord : constord :
hs:=tostr(hpc.valueord); hs:=tostr(hpc.value.valueord);
constpointer : constpointer :
hs:=tostr(hpc.valueordptr); hs:=tostr(hpc.value.valueordptr);
constbool : constbool :
begin begin
if hpc.valueord<>0 then if hpc.value.valueord<>0 then
hs:='TRUE' hs:='TRUE'
else else
hs:='FALSE'; hs:='FALSE';
@ -3244,7 +3244,7 @@ implementation
constnil : constnil :
hs:='nil'; hs:='nil';
constchar : constchar :
hs:=chr(hpc.valueord); hs:=chr(hpc.value.valueord);
constset : constset :
hs:='<set>'; hs:='<set>';
end; end;
@ -5537,7 +5537,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.107 2002-11-19 16:21:29 pierre Revision 1.108 2002-11-22 22:48:10 carl
* memory optimization with tconstsym (1.5%)
Revision 1.107 2002/11/19 16:21:29 pierre
* correct several stabs generation problems * correct several stabs generation problems
Revision 1.106 2002/11/18 17:31:59 peter Revision 1.106 2002/11/18 17:31:59 peter

View File

@ -273,14 +273,22 @@ interface
{$endif GDB} {$endif GDB}
end; end;
tconstvalue = record
case integer of
0: (valueord : tconstexprint);
1: (valueordptr : tconstptruint);
2: (valueptr : pointer; len : longint);
end;
tconstsym = class(tstoredsym) tconstsym = class(tstoredsym)
consttype : ttype; consttype : ttype;
consttyp : tconsttyp; consttyp : tconsttyp;
resstrindex, { needed for resource strings } value : tconstvalue;
valueord : tconstexprint; { used for ordinal values } resstrindex : longint; { needed for resource strings }
(* valueord : tconstexprint; { used for ordinal values }
valueordptr : TConstPtrUInt; { used for pointer values } valueordptr : TConstPtrUInt; { used for pointer values }
valueptr : pointer; { used for string, set, real values } valueptr : pointer; { used for string, set, real values }
len : longint; { len is needed for string length } len : longint; { len is needed for string length }*)
constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint); constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint);
constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype); constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype); constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
@ -1877,85 +1885,74 @@ implementation
constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt); constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=v; value.valueord:=v;
valueordptr:=0;
valueptr:=nil;
ResStrIndex:=0; ResStrIndex:=0;
consttype.reset; consttype.reset;
len:=0;
end; end;
constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype); constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=v; value.valueord:=v;
valueordptr:=0;
valueptr:=nil;
ResStrIndex:=0; ResStrIndex:=0;
consttype:=tt; consttype:=tt;
len:=0;
end; end;
constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype); constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=0; value.valueordptr:=v;
valueordptr:=v;
valueptr:=nil;
ResStrIndex:=0; ResStrIndex:=0;
consttype:=tt; consttype:=tt;
len:=0;
end; end;
constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer); constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=0; value.valueptr:=v;
valueordptr:=0;
valueptr:=v;
ResStrIndex:=0; ResStrIndex:=0;
consttype.reset; consttype.reset;
len:=0;
end; end;
constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype); constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=0; value.valueptr:=v;
valueordptr:=0;
valueptr:=v;
ResStrIndex:=0; ResStrIndex:=0;
consttype:=tt; consttype:=tt;
len:=0;
end; end;
constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint); constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
begin begin
inherited create(n); inherited create(n);
fillchar(value, sizeof(value), #0);
typ:=constsym; typ:=constsym;
consttyp:=t; consttyp:=t;
valueord:=0; value.valueptr:=str;
valueordptr:=0;
valueptr:=str;
consttype.reset; consttype.reset;
len:=l; value.len:=l;
if t=constresourcestring then if t=constresourcestring then
ResStrIndex:=ResourceStrings.Register(name,pchar(valueptr),len); ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
end; end;
@ -1969,53 +1966,51 @@ implementation
typ:=constsym; typ:=constsym;
consttype.reset; consttype.reset;
consttyp:=tconsttyp(ppufile.getbyte); consttyp:=tconsttyp(ppufile.getbyte);
valueord:=0; fillchar(value, sizeof(value), #0);
valueordptr:=0;
valueptr:=nil;
case consttyp of case consttyp of
constint: constint:
valueord:=ppufile.getexprint; value.valueord:=ppufile.getexprint;
constwchar, constwchar,
constbool, constbool,
constchar : constchar :
valueord:=ppufile.getlongint; value.valueord:=ppufile.getlongint;
constord : constord :
begin begin
ppufile.gettype(consttype); ppufile.gettype(consttype);
valueord:=ppufile.getexprint; value.valueord:=ppufile.getexprint;
end; end;
constpointer : constpointer :
begin begin
ppufile.gettype(consttype); ppufile.gettype(consttype);
valueordptr:=ppufile.getptruint; value.valueordptr:=ppufile.getptruint;
end; end;
conststring, conststring,
constresourcestring : constresourcestring :
begin begin
len:=ppufile.getlongint; value.len:=ppufile.getlongint;
getmem(pc,len+1); getmem(pc,value.len+1);
ppufile.getdata(pc^,len); ppufile.getdata(pc^,value.len);
if consttyp=constresourcestring then if consttyp=constresourcestring then
ResStrIndex:=ppufile.getlongint; ResStrIndex:=ppufile.getlongint;
valueptr:=pc; value.valueptr:=pc;
end; end;
constreal : constreal :
begin begin
new(pd); new(pd);
pd^:=ppufile.getreal; pd^:=ppufile.getreal;
valueptr:=pd; value.valueptr:=pd;
end; end;
constset : constset :
begin begin
ppufile.gettype(consttype); ppufile.gettype(consttype);
new(ps); new(ps);
ppufile.getnormalset(ps^); ppufile.getnormalset(ps^);
valueptr:=ps; value.valueptr:=ps;
end; end;
constguid : constguid :
begin begin
new(pguid(valueptr)); new(pguid(value.valueptr));
ppufile.getdata(valueptr^,sizeof(tguid)); ppufile.getdata(value.valueptr^,sizeof(tguid));
end; end;
constnil : ; constnil : ;
else else
@ -2029,13 +2024,13 @@ implementation
case consttyp of case consttyp of
conststring, conststring,
constresourcestring : constresourcestring :
freemem(pchar(valueptr),len+1); freemem(pchar(value.valueptr),value.len+1);
constreal : constreal :
dispose(pbestreal(valueptr)); dispose(pbestreal(value.valueptr));
constset : constset :
dispose(pnormalset(valueptr)); dispose(pnormalset(value.valueptr));
constguid : constguid :
dispose(pguid(valueptr)); dispose(pguid(value.valueptr));
end; end;
inherited destroy; inherited destroy;
end; end;
@ -2061,37 +2056,37 @@ implementation
case consttyp of case consttyp of
constnil : ; constnil : ;
constint: constint:
ppufile.putexprint(valueord); ppufile.putexprint(value.valueord);
constbool, constbool,
constchar : constchar :
ppufile.putlongint(valueord); ppufile.putlongint(value.valueord);
constord : constord :
begin begin
ppufile.puttype(consttype); ppufile.puttype(consttype);
ppufile.putexprint(valueord); ppufile.putexprint(value.valueord);
end; end;
constpointer : constpointer :
begin begin
ppufile.puttype(consttype); ppufile.puttype(consttype);
ppufile.putptruint(valueordptr); ppufile.putptruint(value.valueordptr);
end; end;
conststring, conststring,
constresourcestring : constresourcestring :
begin begin
ppufile.putlongint(len); ppufile.putlongint(value.len);
ppufile.putdata(pchar(valueptr)^,len); ppufile.putdata(pchar(value.valueptr)^,value.len);
if consttyp=constresourcestring then if consttyp=constresourcestring then
ppufile.putlongint(ResStrIndex); ppufile.putlongint(ResStrIndex);
end; end;
constreal : constreal :
ppufile.putreal(pbestreal(valueptr)^); ppufile.putreal(pbestreal(value.valueptr)^);
constset : constset :
begin begin
ppufile.puttype(consttype); ppufile.puttype(consttype);
ppufile.putnormalset(valueptr^); ppufile.putnormalset(value.valueptr^);
end; end;
constguid : constguid :
ppufile.putdata(valueptr^,sizeof(tguid)); ppufile.putdata(value.valueptr^,sizeof(tguid));
else else
internalerror(13); internalerror(13);
end; end;
@ -2105,16 +2100,16 @@ implementation
{even GDB v4.16 only now 'i' 'r' and 'e' !!!} {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
case consttyp of case consttyp of
conststring : begin conststring : begin
st := 's'''+strpas(pchar(valueptr))+''''; st := 's'''+strpas(pchar(value.valueptr))+'''';
end; end;
constbool, constbool,
constint, constint,
constord, constord,
constchar : st := 'i'+int64tostr(valueord); constchar : st := 'i'+int64tostr(value.valueord);
constpointer : constpointer :
st := 'i'+int64tostr(valueordptr); st := 'i'+int64tostr(value.valueordptr);
constreal : begin constreal : begin
system.str(pbestreal(valueptr)^,st); system.str(pbestreal(value.valueptr)^,st);
st := 'r'+st; st := 'r'+st;
end; end;
{ if we don't know just put zero !! } { if we don't know just put zero !! }
@ -2504,7 +2499,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.73 2002-11-18 17:31:59 peter Revision 1.74 2002-11-22 22:48:11 carl
* memory optimization with tconstsym (1.5%)
Revision 1.73 2002/11/18 17:31:59 peter
* pass proccalloption to ret_in_xxx and push_xxx functions * pass proccalloption to ret_in_xxx and push_xxx functions
Revision 1.72 2002/11/17 16:31:57 carl Revision 1.72 2002/11/17 16:31:57 carl