mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-05 12:38:32 +02:00
* Removed 'first' field and 'packed' attribute from TAnsiRec and TUnicodeRec. Removing 'packed' should yield more efficient code on alignment-sensitive targets, while removing 'first' effectively makes two records identical to each other. Further cleanup is possible, but let's see the test suite results before proceeding.
git-svn-id: trunk@20275 -
This commit is contained in:
parent
c44ce80585
commit
180686e429
@ -35,7 +35,7 @@
|
||||
|
||||
Type
|
||||
PAnsiRec = ^TAnsiRec;
|
||||
TAnsiRec = Packed Record
|
||||
TAnsiRec = Record
|
||||
CodePage : TSystemCodePage;
|
||||
ElementSize : Word;
|
||||
{$ifdef CPU64}
|
||||
@ -44,12 +44,10 @@ Type
|
||||
{$endif CPU64}
|
||||
Ref : SizeInt;
|
||||
Len : SizeInt;
|
||||
First : AnsiChar;
|
||||
end;
|
||||
|
||||
Const
|
||||
AnsiRecLen = SizeOf(TAnsiRec);
|
||||
AnsiFirstOff = SizeOf(TAnsiRec)-1;
|
||||
AnsiFirstOff = SizeOf(TAnsiRec);
|
||||
|
||||
{****************************************************************************
|
||||
Internal functions, not in interface.
|
||||
@ -64,15 +62,15 @@ Var
|
||||
P : Pointer;
|
||||
begin
|
||||
{ request a multiple of 16 because the heap manager alloctes anyways chunks of 16 bytes }
|
||||
GetMem(P,Len+AnsiRecLen);
|
||||
GetMem(P,Len+(AnsiFirstOff+sizeof(char)));
|
||||
If P<>Nil then
|
||||
begin
|
||||
PAnsiRec(P)^.Ref:=1; { Set reference count }
|
||||
PAnsiRec(P)^.Len:=0; { Initial length }
|
||||
PAnsiRec(P)^.CodePage:=DefaultSystemCodePage;
|
||||
PAnsiRec(P)^.ElementSize:=SizeOf(AnsiChar);
|
||||
PAnsiRec(P)^.First:=#0; { Terminating #0 }
|
||||
inc(p,AnsiFirstOff); { Points to string now }
|
||||
PAnsiChar(P)^:=#0; { Terminating #0 }
|
||||
end;
|
||||
NewAnsiString:=P;
|
||||
end;
|
||||
@ -692,11 +690,11 @@ begin
|
||||
begin
|
||||
Temp:=Pointer(s)-AnsiFirstOff;
|
||||
lens:=MemSize(Temp);
|
||||
lena:=AnsiRecLen+L;
|
||||
lena:=AnsiFirstOff+L+sizeof(AnsiChar);
|
||||
{ allow shrinking string if that saves at least half of current size }
|
||||
if (lena>lens) or ((lens>32) and (lena<=(lens div 2))) then
|
||||
begin
|
||||
reallocmem(Temp,AnsiRecLen+L);
|
||||
reallocmem(Temp,lena);
|
||||
Pointer(S):=Temp+AnsiFirstOff;
|
||||
end;
|
||||
end
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
Type
|
||||
PUnicodeRec = ^TUnicodeRec;
|
||||
TUnicodeRec = Packed Record
|
||||
TUnicodeRec = Record
|
||||
CodePage : TSystemCodePage;
|
||||
ElementSize : Word;
|
||||
{$ifdef CPU64}
|
||||
@ -44,12 +44,10 @@ Type
|
||||
{$endif CPU64}
|
||||
Ref : SizeInt;
|
||||
Len : SizeInt;
|
||||
First : UnicodeChar;
|
||||
end;
|
||||
|
||||
Const
|
||||
UnicodeRecLen = SizeOf(TUnicodeRec);
|
||||
UnicodeFirstOff = SizeOf(TUnicodeRec)-sizeof(UnicodeChar);
|
||||
UnicodeFirstOff = SizeOf(TUnicodeRec);
|
||||
|
||||
{
|
||||
Default UnicodeChar <-> Char conversion is to only convert the
|
||||
@ -170,15 +168,15 @@ Function NewUnicodeString(Len : SizeInt) : Pointer;
|
||||
Var
|
||||
P : Pointer;
|
||||
begin
|
||||
GetMem(P,Len*sizeof(UnicodeChar)+UnicodeRecLen);
|
||||
GetMem(P,Len*sizeof(UnicodeChar)+(UnicodeFirstOff+sizeof(UnicodeChar)));
|
||||
If P<>Nil then
|
||||
begin
|
||||
PUnicodeRec(P)^.Len:=Len; { Initial length }
|
||||
PUnicodeRec(P)^.Ref:=1; { Initial Refcount }
|
||||
PUnicodeRec(P)^.CodePage:=DefaultUnicodeCodePage;
|
||||
PUnicodeRec(P)^.ElementSize:=SizeOf(UnicodeChar);
|
||||
PUnicodeRec(P)^.First:=#0; { Terminating #0 }
|
||||
inc(p,UnicodeFirstOff); { Points to string now }
|
||||
PUnicodeChar(P)^:=#0; { Terminating #0 }
|
||||
end
|
||||
else
|
||||
UnicodeStringError;
|
||||
@ -848,7 +846,7 @@ begin
|
||||
begin
|
||||
Temp:=Pointer(s)-UnicodeFirstOff;
|
||||
lens:=MemSize(Temp);
|
||||
lena:=SizeUInt(L*sizeof(UnicodeChar)+UnicodeRecLen);
|
||||
lena:=SizeUInt(L*sizeof(UnicodeChar)+(UnicodeFirstOff+sizeof(UnicodeChar)));
|
||||
if (lena>lens) or ((lens>32) and (lena<=(lens div 2))) then
|
||||
begin
|
||||
reallocmem(Temp, lena);
|
||||
|
Loading…
Reference in New Issue
Block a user