Skip to content

Commit

Permalink
huge refactoring to use record instead of object
Browse files Browse the repository at this point in the history
whenever possible, and therefore circumvent Delphi compiler bugs
  • Loading branch information
Arnaud Bouchez committed Aug 17, 2023
1 parent d630cf2 commit e29d7f2
Show file tree
Hide file tree
Showing 28 changed files with 566 additions and 139 deletions.
16 changes: 16 additions & 0 deletions src/core/mormot.core.base.pas
Expand Up @@ -1693,7 +1693,11 @@ function FromU64(const Values: array of QWord): TQWordDynArray;
/// used to store and retrieve Words in a sorted array
// - this "object" (i.e. record with methods) should be filled with zeros
// before use - e.g. when defined as a private member of a class
{$ifdef USERECORDWITHMETHODS}
TSortedWordArray = record
{$else}
TSortedWordArray = object
{$endif USERECORDWITHMETHODS}
public
/// the actual 16-bit word storage
Values: TWordDynArray;
Expand All @@ -1712,7 +1716,11 @@ function FromU64(const Values: array of QWord): TQWordDynArray;
/// used to store and retrieve Integers in a sorted array
// - this "object" (i.e. record with methods) should be filled with zeros
// before use - e.g. when defined as a private member of a class
{$ifdef USERECORDWITHMETHODS}
TSortedIntegerArray = record
{$else}
TSortedIntegerArray = object
{$endif USERECORDWITHMETHODS}
public
/// the actual 32-bit integers storage
Values: TIntegerDynArray;
Expand Down Expand Up @@ -2861,7 +2869,11 @@ function IsAnsiCompatibleW(PW: PWideChar; Len: PtrInt): boolean; overload;
// - SeedGenerator() makes it a sequence generator - or encryptor via Fill()
// - when used as random generator (default when initialized with 0), Seed()
// will gather and hash some system entropy
{$ifdef USERECORDWITHMETHODS}
TLecuyer = record
{$else}
TLecuyer = object
{$endif USERECORDWITHMETHODS}
public
rs1, rs2, rs3, seedcount: cardinal;
/// force a random seed of the generator from current system state
Expand Down Expand Up @@ -3061,7 +3073,11 @@ function EventEquals(const eventA, eventB): boolean;
// - all Init() methods will allocate 16 more bytes, for a trailing #0 and
// to ensure our fast JSON parsing won't trigger any GPF (since it may read
// up to 4 bytes ahead via its PInteger() trick) or any SSE4.2 function
{$ifdef USERECORDWITHMETHODS}
TSynTempBuffer = record
{$else}
TSynTempBuffer = object
{$endif USERECORDWITHMETHODS}
public
/// the text/binary length, in bytes, excluding the trailing #0
len: PtrInt;
Expand Down
4 changes: 4 additions & 0 deletions src/core/mormot.core.buffers.pas
Expand Up @@ -9889,7 +9889,11 @@ function IsStreamBuffer(S: TStream): boolean;
twlCode4,
twlCode3);

{$ifdef USERECORDWITHMETHODS}
TTextWriterEscape = record
{$else}
TTextWriterEscape = object
{$endif USERECORDWITHMETHODS}
public
P, B, P2, B2: PUtf8Char;
W: TTextWriter;
Expand Down
8 changes: 8 additions & 0 deletions src/core/mormot.core.data.pas
Expand Up @@ -8073,7 +8073,11 @@ function TDynArray.FastLocateOrAddSorted(const Item; wasAdded: PBoolean): intege

type
// internal structure used to make QuickSort faster & with less stack usage
{$ifdef USERECORDWITHMETHODS}
TDynArrayQuickSort = record
{$else}
TDynArrayQuickSort = object
{$endif USERECORDWITHMETHODS}
public
Compare: TDynArraySortCompare;
CompareEvent: TOnDynArraySortCompare;
Expand Down Expand Up @@ -9871,7 +9875,11 @@ function TDynArrayHasher.Find(Item: pointer; aHashCode: cardinal): PtrInt;
end;

type
{$ifdef USERECORDWITHMETHODS}
TFastReHash = record
{$else}
TFastReHash = object // dedicated object for better register allocation
{$endif USERECORDWITHMETHODS}
public
hc: cardinal;
{$ifdef DYNARRAYHASHCOLLISIONCOUNT}
Expand Down
4 changes: 4 additions & 0 deletions src/core/mormot.core.datetime.pas
Expand Up @@ -679,7 +679,11 @@ function UnixMSTimePeriodToString(const UnixMSTime: TUnixMSTime;
// temporary conversion in such case
// - TTimeLogBits.Value needs up to 40-bit precision, so features exact
// representation as JavaScript numbers (stored in a 52-bit mantissa)
{$ifdef USERECORDWITHMETHODS}
TTimeLogBits = record
{$else}
TTimeLogBits = object
{$endif USERECORDWITHMETHODS}
public
/// the bit-encoded value itself, which follows an abstract "year" of 16
// months of 32 days of 32 hours of 64 minutes of 64 seconds
Expand Down
7 changes: 4 additions & 3 deletions src/core/mormot.core.interfaces.pas
Expand Up @@ -3472,7 +3472,8 @@ procedure TInterfacedObjectFake.FakeCallSetJsonToStack(
repeat
if resultAsJsonObject then
begin
Val := GetJsonPropName(c.Json, @ValLen);
Val := GetJsonPropName(
c.{$ifdef USERECORDWITHMETHODS}Get.{$endif}Json, @ValLen);
if Val = nil then
// end of JSON object
break;
Expand All @@ -3499,7 +3500,7 @@ procedure TInterfacedObjectFake.FakeCallSetJsonToStack(
end;
if c.Json = nil then
break;
c.Json := GotoNextNotSpace(c.Json);
c.{$ifdef USERECORDWITHMETHODS}Get.{$endif}Json := GotoNextNotSpace(c.Json);
if resultAsJsonObject then
begin
if (c.Json^ = #0) or
Expand Down Expand Up @@ -7551,7 +7552,7 @@ function TInterfaceMethodExecute.ExecuteJson(const Instances: array of pointer;
continue
else
// value to be retrieved from JSON object
ctxt.Json := ParObjValues[a]
ctxt.{$ifdef USERECORDWITHMETHODS}Get.{$endif}Json := ParObjValues[a]
else if ctxt.Json = nil then
break; // premature end of ..] (ParObjValuesUsed=false)
if arg^.ValueType = imvInterface then
Expand Down

0 comments on commit e29d7f2

Please sign in to comment.