Skip to content

Commit dbe1f53

Browse files
author
Arnaud Bouchez
committed
all: new TByteToByte/TByteToAnsiChar and similar types
1 parent ffd797a commit dbe1f53

25 files changed

+78
-75
lines changed

src/core/mormot.core.base.pas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,17 @@ interface
484484
PObjectArray = ^TObjectArray;
485485
TPtrIntArray = array[ 0 .. MaxInt div SizeOf(PtrInt) - 1 ] of PtrInt;
486486
PPtrIntArray = ^TPtrIntArray;
487+
TByteToByte = array[byte] of byte;
488+
TByteToAnsiChar = array[byte] of AnsiChar;
489+
TByteToWideChar = array[byte] of WideChar;
490+
/// type of mormot.core.unicode TNormTable lookup table
491+
TAnsiCharToAnsiChar = array[AnsiChar] of AnsiChar;
492+
/// type of a lookup table used for fast two-digit chars conversion
493+
TAnsiCharToWord = array[AnsiChar] of word;
494+
PAnsiCharToWord = ^TAnsiCharToWord;
495+
/// type of a lookup table used for fast two-digit chars conversion
496+
TByteToWord = array[byte] of word;
497+
PByteToWord = ^TByteToWord;
487498
PInt64Rec = ^Int64Rec;
488499
PLongRec = ^LongRec;
489500
PPShortString = ^PShortString;

src/core/mormot.core.buffers.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8636,7 +8636,7 @@ function UrlDecodeDouble(U: PUtf8Char; const Upper: RawUtf8;
86368636

86378637
function UrlDecodeNeedParameters(U, CsvNames: PUtf8Char): boolean;
86388638
var
8639-
tmp: array[byte] of AnsiChar;
8639+
tmp: TByteToAnsiChar;
86408640
L: integer;
86418641
Beg: PUtf8Char;
86428642
// UrlDecodeNeedParameters('price=20.45&where=LastName%3D','price,where') will

src/core/mormot.core.data.pas

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,7 +3964,7 @@ function GetSectionContent(SectionFirstLine: PUtf8Char): RawUtf8;
39643964
function GetSectionContent(const Content, SectionName: RawUtf8): RawUtf8;
39653965
var
39663966
P: PUtf8Char;
3967-
UpperSection: array[byte] of AnsiChar;
3967+
UpperSection: TByteToAnsiChar;
39683968
begin
39693969
P := pointer(Content);
39703970
PWord(UpperCopy255(UpperSection{%H-}, SectionName))^ := ord(']');
@@ -3978,7 +3978,7 @@ function DeleteSection(var Content: RawUtf8; const SectionName: RawUtf8;
39783978
EraseSectionHeader: boolean): boolean;
39793979
var
39803980
P: PUtf8Char;
3981-
UpperSection: array[byte] of AnsiChar;
3981+
UpperSection: TByteToAnsiChar;
39823982
begin
39833983
result := false; // no modification
39843984
P := pointer(Content);
@@ -4036,7 +4036,7 @@ procedure ReplaceSection(SectionFirstLine: PUtf8Char; var Content: RawUtf8;
40364036

40374037
procedure ReplaceSection(var Content: RawUtf8; const SectionName, NewSectionContent: RawUtf8);
40384038
var
4039-
UpperSection: array[byte] of AnsiChar;
4039+
UpperSection: TByteToAnsiChar;
40404040
P: PUtf8Char;
40414041
begin
40424042
P := pointer(Content);
@@ -4069,7 +4069,7 @@ function FindIniNameValueInteger(P: PUtf8Char; const UpperName: RawUtf8): PtrInt
40694069
function FindIniEntry(const Content, Section, Name, DefaultValue: RawUtf8): RawUtf8;
40704070
var
40714071
P: PUtf8Char;
4072-
UpperSection, UpperName: array[byte] of AnsiChar;
4072+
UpperSection, UpperName: TByteToAnsiChar;
40734073
begin
40744074
result := DefaultValue;
40754075
P := pointer(Content);
@@ -4175,7 +4175,7 @@ procedure UpdateIniEntry(var Content: RawUtf8;
41754175
SectionFound: boolean;
41764176
i, UpperNameLength: PtrInt;
41774177
V: RawUtf8;
4178-
UpperSection, UpperName: array[byte] of AnsiChar;
4178+
UpperSection, UpperName: TByteToAnsiChar;
41794179
begin
41804180
UpperNameLength := length(Name);
41814181
PWord(UpperCopy255Buf(
@@ -4248,7 +4248,7 @@ function IniToObject(const Ini: RawUtf8; Instance: TObject;
42484248
section, nested, json: PUtf8Char;
42494249
name: PAnsiChar;
42504250
n, v: RawUtf8;
4251-
up: array[byte] of AnsiChar;
4251+
up: TByteToAnsiChar;
42524252
begin
42534253
result := false; // true when at least one property has been read
42544254
if (Ini = '') or
@@ -4462,7 +4462,7 @@ function HashIntern(P: PUtf8Char; L: PtrUInt): cardinal;
44624462

44634463
function HashInternI(P: PUtf8Char; L: PtrUInt): cardinal;
44644464
var
4465-
tmp: array[byte] of AnsiChar; // avoid slow heap allocation
4465+
tmp: TByteToAnsiChar; // avoid slow heap allocation
44664466
begin
44674467
if (P <> nil) and
44684468
(L <> 0) then
@@ -5368,7 +5368,7 @@ function TRawUtf8List.EqualValueAt(Index: PtrInt; const aText: RawUtf8): boolean
53685368

53695369
function TRawUtf8List.IndexOfName(const Name: RawUtf8): PtrInt;
53705370
var
5371-
UpperName: array[byte] of AnsiChar;
5371+
UpperName: TByteToAnsiChar;
53725372
table: PNormTable;
53735373
begin
53745374
if self <> nil then
@@ -6549,7 +6549,7 @@ function BinarySaveLength(Data: pointer; Info: PRttiInfo; Len: PInteger;
65496549
var
65506550
size: integer;
65516551
W: TBufferWriter; // not very fast, but good enough (RecordSave don't use it)
6552-
temp: array[byte] of byte; // will use mostly TFakeWriterStream.Write()
6552+
temp: TByteToByte; // will use mostly TFakeWriterStream.Write()
65536553
save: TRttiBinarySave;
65546554
begin
65556555
save := RTTI_BINARYSAVE[Info^.Kind];
@@ -9031,7 +9031,7 @@ function HashAnsiString(Item: PAnsiChar; Hasher: THasher): cardinal;
90319031

90329032
function HashAnsiStringI(Item: PUtf8Char; Hasher: THasher): cardinal;
90339033
var
9034-
tmp: array[byte] of AnsiChar; // avoid any slow heap allocation
9034+
tmp: TByteToAnsiChar; // avoid any slow heap allocation
90359035
begin
90369036
Item := PPointer(Item)^; // passed as non-nil PAnsiString reference
90379037
if Item <> nil then
@@ -9062,7 +9062,7 @@ function HashSynUnicode(Item: PAnsiChar; Hasher: THasher): cardinal;
90629062

90639063
function HashSynUnicodeI(Item: PSynUnicode; Hasher: THasher): cardinal;
90649064
var
9065-
tmp: array[byte] of AnsiChar; // avoid slow heap allocation
9065+
tmp: TByteToAnsiChar; // avoid slow heap allocation
90669066
begin
90679067
if PtrUInt(Item^) <> 0 then
90689068
result := Hasher(HashSeed, tmp{%H-}, UpperCopy255W(tmp{%H-}, Item^) - {%H-}tmp)
@@ -9081,7 +9081,7 @@ function HashWideString(Item: PWideString; Hasher: THasher): cardinal;
90819081

90829082
function HashWideStringI(Item: PWideString; Hasher: THasher): cardinal;
90839083
var
9084-
tmp: array[byte] of AnsiChar; // avoid slow heap allocation
9084+
tmp: TByteToAnsiChar; // avoid slow heap allocation
90859085
begin
90869086
if PtrUInt(Item^) <> 0 then
90879087
result := Hasher(HashSeed, tmp{%H-},
@@ -9101,7 +9101,7 @@ function HashPUtf8Char(Item: PAnsiChar; Hasher: THasher): cardinal;
91019101

91029102
function HashPUtf8CharI(Item: PUtf8Char; Hasher: THasher): cardinal;
91039103
var
9104-
tmp: array[byte] of AnsiChar; // avoid slow heap allocation
9104+
tmp: TByteToAnsiChar; // avoid slow heap allocation
91059105
begin
91069106
Item := PPointer(Item)^; // passed as non-nil PPUtf8Char reference
91079107
if Item <> nil then
@@ -9154,7 +9154,7 @@ function Hash512(Item: pointer; Hasher: THasher): cardinal;
91549154
function VariantHash(const value: variant; CaseInsensitive: boolean;
91559155
Hasher: THasher): cardinal;
91569156
var
9157-
tmp: array[byte] of AnsiChar; // avoid heap allocation
9157+
tmp: TByteToAnsiChar; // avoid heap allocation
91589158
vt: cardinal;
91599159
S: TStream;
91609160
W: TTextWriter;

src/core/mormot.core.json.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ EJsonException = class(ESynException);
118118
// - 1 = JSON_ESCAPE_ENDINGZERO indicates #0 (end of string)
119119
// - 2 = JSON_ESCAPE_UNICODEHEX should be escaped as \u00xx
120120
// - b,t,n,f,r,\," as escaped character for #8,#9,#10,#12,#13,\,"
121-
JSON_ESCAPE: array[byte] of byte;
121+
JSON_ESCAPE: TByteToByte;
122122

123123
/// 256-byte lookup table for fast branchless JSON text un-escaping
124124
// - #0 = JSON_UNESCAPE_UNEXPECTED for unexpected #0 or control char
125125
// - #1 = JSON_UNESCAPE_UTF16 for '\u0123' UTF-16 pattern
126126
// - #8,#9,#10,#12,#13 as unescaped char from b,t,n,f,r
127127
// - other characters are litterals and should be written as such
128-
JSON_UNESCAPE: array[AnsiChar] of AnsiChar;
128+
JSON_UNESCAPE: TAnsiCharToAnsiChar;
129129

130130
/// how many initial chars of a JSON array are parsed for intial capacity
131131
// - used e.g. by _JL_DynArray() and TDocVariantData.InitJsonInPlace()
@@ -4298,7 +4298,7 @@ function JsonObjectItem(P: PUtf8Char; PropName: PUtf8Char; PropNameLen: PtrInt;
42984298
PropNameFound: PRawUtf8): PUtf8Char;
42994299
var
43004300
name: ShortString; // no memory allocation nor P^ modification
4301-
PropNameUpper: array[byte] of AnsiChar;
4301+
PropNameUpper: TByteToAnsiChar;
43024302
parser: TJsonGotoEndParser;
43034303
begin
43044304
if P <> nil then

src/core/mormot.core.os.posix.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ function kenv(action: integer; name, value: PAnsiChar; len: integer): integer;
27672767

27682768
function GetSmbEfiMem: RawByteString;
27692769
var
2770-
tmp: array[byte] of AnsiChar;
2770+
tmp: TByteToAnsiChar;
27712771
xaddr: PtrUInt;
27722772
begin
27732773
result := '';
@@ -2803,7 +2803,7 @@ const
28032803
procedure _DirectSmbiosInfo(out info: TSmbiosBasicInfos);
28042804
var
28052805
i: PtrInt;
2806-
tmp: array[byte] of AnsiChar;
2806+
tmp: TByteToAnsiChar;
28072807
begin
28082808
for i := 0 to high(_KNOWN) do
28092809
with _KNOWN[i] do

src/core/mormot.core.os.security.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,10 @@ function SecAclToBinary(const acl: TSecAcl): RawByteString;
10161016
Int: TRawAceOperandInt);
10171017
sctOctetString: (
10181018
OctetBytes: cardinal;
1019-
Octet: array[byte] of byte);
1019+
Octet: TByteToByte);
10201020
sctComposite: (
10211021
CompositeBytes: cardinal;
1022-
Composite: array[byte] of byte);
1022+
Composite: TByteToByte);
10231023
sctSid: (
10241024
SidBytes: cardinal;
10251025
Sid: TSid);
@@ -1030,7 +1030,7 @@ function SecAclToBinary(const acl: TSecAcl): RawByteString;
10301030
sctResourceAttribute,
10311031
sctDeviceAttribute: (
10321032
UnicodeBytes: cardinal;
1033-
Unicode: array[byte] of WideChar);
1033+
Unicode: TByteToWideChar);
10341034
end;
10351035
PRawAceOperand = ^TRawAceOperand;
10361036

@@ -5237,7 +5237,7 @@ function CurrentUserIsAdmin: boolean;
52375237
function LookupSid(sid: PSid; out name, domain: RawUtf8;
52385238
const server: RawUtf8): TSidType;
52395239
var
5240-
n, d: array[byte] of WideChar;
5240+
n, d: TByteToWideChar;
52415241
s: TSynTempBuffer;
52425242
nl, dl, use: cardinal;
52435243
begin

src/core/mormot.core.os.windows.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ const
10661066

10671067
function GetExecutableName(aAddress: pointer): TFileName;
10681068
var
1069-
tmp: array[byte] of WideChar;
1069+
tmp: TByteToWideChar;
10701070
hm: HMODULE;
10711071
begin
10721072
result := '';
@@ -2892,7 +2892,7 @@ end;
28922892

28932893
procedure GetUserHost(out User, Host: RawUtf8);
28942894
var
2895-
tmp: array[byte] of WideChar;
2895+
tmp: TByteToWideChar;
28962896
tmpsize: cardinal;
28972897
begin
28982898
tmpsize := SizeOf(tmp);

src/core/mormot.core.rtti.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ procedure TRttiEnumType.AddCaptionStrings(Strings: TStrings;
35923592
UsedValuesBits: pointer);
35933593
var
35943594
i, L: PtrInt;
3595-
Line: array[byte] of AnsiChar;
3595+
Line: TByteToAnsiChar;
35963596
P: PAnsiChar;
35973597
V: PShortString;
35983598
s: string;
@@ -6319,7 +6319,7 @@ function GetSetCsvValue(aTypeInfo: PRttiInfo; Csv: PUtf8Char): QWord;
63196319

63206320
procedure GetCaptionFromTrimmed(PS: PShortString; var result: string);
63216321
var
6322-
tmp: array[byte] of AnsiChar;
6322+
tmp: TByteToAnsiChar;
63236323
L: integer;
63246324
begin
63256325
L := ord(PS^[0]);

src/core/mormot.core.search.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ TParserAbstract = class(TSynPersistent)
606606
fWords: array of TExprNodeWordAbstract;
607607
fWordCount: integer;
608608
fNoWordIsAnd: boolean;
609-
fFoundStack: array[byte] of AnsiChar; // simple stack-based virtual machine
609+
fFoundStack: TByteToAnsiChar; // simple stack-based virtual machine
610610
procedure ParseNextCurrentWord; virtual; abstract;
611611
function ParseExpr: TExprNode;
612612
function ParseFactor: TExprNode;

src/core/mormot.core.text.pas

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,14 +2262,6 @@ function IsInvalidHttpHeader(head: PUtf8Char; headlen: PtrInt): boolean;
22622262

22632263
{ **************** Hexadecimal Text And Binary Conversion }
22642264

2265-
type
2266-
/// type of a lookup table used for fast two-digit chars conversion
2267-
TAnsiCharToWord = array[AnsiChar] of word;
2268-
PAnsiCharToWord = ^TAnsiCharToWord;
2269-
/// type of a lookup table used for fast two-digit chars conversion
2270-
TByteToWord = array[byte] of word;
2271-
PByteToWord = ^TByteToWord;
2272-
22732265
var
22742266
/// conversion table from hexa chars into 0..15 binary data
22752267
// - returns 255 for any character out of 0..9,A..Z,a..z range

src/core/mormot.core.unicode.pas

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TUtf8Table = record
5454
/// the number of extra bytes in addition to the first UTF-8 byte
5555
// - since RFC 3629, only values within the 0..3 range should appear, i.e.
5656
// up to UTF8_MAXUTF16 within the UTF-16 surrogates range
57-
Lookup: array[byte] of byte;
57+
Lookup: TByteToByte;
5858
/// retrieve a >127 UCS-4 CodePoint from an UTF-8 sequence
5959
function GetHighUtf8Ucs4(var U: PUtf8Char): Ucs4CodePoint;
6060
end;
@@ -1187,12 +1187,12 @@ function StringToWinAnsi(const Text: string): WinAnsiString;
11871187

11881188
type
11891189
/// lookup table used for fast case conversion
1190-
TNormTable = packed array[AnsiChar] of AnsiChar;
1190+
TNormTable = TAnsiCharToAnsiChar;
11911191
/// pointer to a lookup table used for fast case conversion
11921192
PNormTable = ^TNormTable;
11931193

11941194
/// lookup table used for fast case conversion
1195-
TNormTableByte = packed array[byte] of byte;
1195+
TNormTableByte = TByteToByte;
11961196
/// pointer to a lookup table used for fast case conversion
11971197
PNormTableByte = ^TNormTableByte;
11981198

@@ -1572,15 +1572,15 @@ function GetLineContains(p, pEnd, up: PUtf8Char): boolean;
15721572
// - used internally for short keys match or case-insensitive hash
15731573
// - returns final dest pointer
15741574
// - will copy up to 255 AnsiChar (expect the dest buffer to be defined e.g. as
1575-
// array[byte] of AnsiChar on the caller stack)
1575+
// TByteToAnsiChar on the caller stack)
15761576
function UpperCopy255(dest: PAnsiChar; const source: RawUtf8): PAnsiChar; overload;
15771577
{$ifdef HASINLINE}inline;{$endif}
15781578

15791579
/// copy source^ into a 256 chars dest^ buffer with 7-bit upper case conversion
15801580
// - used internally for short keys match or case-insensitive hash
15811581
// - returns final dest pointer
15821582
// - will copy up to 255 AnsiChar (expect the dest buffer to be defined e.g. as
1583-
// array[byte] of AnsiChar on the caller stack)
1583+
// TByteToAnsiChar on the caller stack)
15841584
function UpperCopy255Buf(dest: PAnsiChar; source: PUtf8Char; sourceLen: PtrInt): PAnsiChar;
15851585

15861586
/// copy source into dest^ with WinAnsi 8-bit upper case conversion
@@ -9129,7 +9129,7 @@ procedure CamelCase(P: PAnsiChar; len: PtrInt; var s: RawUtf8; const isWord: TSy
91299129
var
91309130
i: PtrInt;
91319131
d: PAnsiChar;
9132-
tmp: array[byte] of AnsiChar;
9132+
tmp: TByteToAnsiChar;
91339133
begin
91349134
if len > SizeOf(tmp) then
91359135
len := SizeOf(tmp);
@@ -9198,7 +9198,7 @@ function LowerCamelCase(const text: RawUtf8): RawUtf8;
91989198

91999199
procedure SnakeCase(P: PAnsiChar; len: PtrInt; var s: RawUtf8);
92009200
var
9201-
tmp: array[byte] of AnsiChar;
9201+
tmp: TByteToAnsiChar;
92029202
d: PAnsiChar;
92039203
flags, last: TSnakeCase;
92049204
begin
@@ -9247,7 +9247,7 @@ function SnakeCase(const text: RawUtf8): RawUtf8;
92479247

92489248
function IsReservedKeyWord(const aName: RawUtf8): boolean;
92499249
var
9250-
up: array[byte] of AnsiChar;
9250+
up: TByteToAnsiChar;
92519251
begin
92529252
UpperCopy255Buf(@up, pointer(aName), length(aName))^ := #0;
92539253
result := FastFindPUtf8CharSorted(
@@ -9267,7 +9267,7 @@ function SanitizePascalName(const aName: RawUtf8; KeyWordCheck: boolean): RawUtf
92679267

92689268
procedure GetCaptionFromPCharLen(P: PUtf8Char; out result: string);
92699269
var
9270-
tmp: array[byte] of AnsiChar;
9270+
tmp: TByteToAnsiChar;
92719271
begin
92729272
if P = nil then
92739273
exit;
@@ -9679,7 +9679,7 @@ function FastFindPUtf8CharSorted(P: PPUtf8CharArray; R: PtrInt; Value: PUtf8Char
96799679
function FastFindUpperPUtf8CharSorted(P: PPUtf8CharArray; R: PtrInt;
96809680
Value: PUtf8Char; ValueLen: PtrInt): PtrInt;
96819681
var
9682-
tmp: array[byte] of AnsiChar;
9682+
tmp: TByteToAnsiChar;
96839683
begin
96849684
UpperCopy255Buf(@tmp, Value, ValueLen)^ := #0;
96859685
result := FastFindPUtf8CharSorted(P, R, @tmp);

0 commit comments

Comments
 (0)