Permalink
Browse files

new FastSetString() signature for UTF-8 content

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Aug 16, 2018
1 parent 5b701c0 commit c727eaa959294f5a0610bebca41074e5f004461e
Showing with 24 additions and 27 deletions.
  1. +3 −3 SQLite3/mORMot.pas
  2. +18 −21 SynCommons.pas
  3. +1 −1 SynopseCommit.inc
  4. +2 −2 lizard.lpi
@@ -21652,7 +21652,7 @@ procedure ValueVarToVariant(Value: PUTF8Char; ValueLen: integer; fieldType: TSQL
result.VDouble := GetExtended(Value,err);
if err<>0 then begin
result.VType := varString;
FastSetString(result.VAny,Value,ValueLen);
FastSetString(RawUTF8(result.VAny),Value,ValueLen);
end;
end;
sftDateTime, sftDateTimeMS:
@@ -21666,7 +21666,7 @@ procedure ValueVarToVariant(Value: PUTF8Char; ValueLen: integer; fieldType: TSQL
sftTimeLog, sftModTime, sftCreateTime, sftUnixTime, sftUnixMSTime:
SetInt64(Value,result.VInt64);
sftAnsiText, sftUTF8Text:
FastSetString(result.VAny,Value,ValueLen);
FastSetString(RawUTF8(result.VAny),Value,ValueLen);
sftBlobCustom, sftBlob:
BlobToTSQLRawBlob(Value,TSQLRawBlob(result.VAny));
{$ifndef NOVARIANTS}sftVariant, sftNullable,{$endif}
@@ -52626,7 +52626,7 @@ procedure TSQLVirtualTableCursor.SetColumn(var aResult: TSQLVar;
begin
aResult.Options := [];
aResult.VType := ftUTF8;
FastSetString(fColumnTemp,aValue,aValueLength); // temporary copy
FastSetString(RawUTF8(fColumnTemp),aValue,aValueLength); // temporary copy
aResult.VText := pointer(fColumnTemp);
end;
@@ -949,7 +949,7 @@ {$ifdef UNICODE}TSynTempWriter = record{$else}TSynTempWriter = object{$endif}
/// equivalence to SetString(s,nil,len) function
// - faster especially under FPC
procedure FastSetString(var s; p: pointer; len: PtrInt);
procedure FastSetString(var s: RawUTF8; p: pointer; len: PtrInt);
/// equivalence to SetString(s,nil,len) function with a specific code page
// - faster especially under FPC
@@ -18371,7 +18371,7 @@ function TSynAnsiUTF8.UTF8BufferToAnsi(Dest: PAnsiChar; Source: PUTF8Char;
procedure TSynAnsiUTF8.UTF8BufferToAnsi(Source: PUTF8Char; SourceChars: Cardinal;
var result: RawByteString);
begin
FastSetString(result,Source,SourceChars);
FastSetString(RawUTF8(result),Source,SourceChars);
end;
function TSynAnsiUTF8.UTF8ToAnsi(const UTF8: RawUTF8): RawByteString;
@@ -20928,22 +20928,19 @@ procedure Exchg(P1,P2: PAnsiChar; count: PtrInt);
PStrRec = ^TStrRec;
/// map the Delphi/FPC string header, as defined in System.pas
TStrRec =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
{$ifdef FPC}
{$ifdef FPC} // see TAnsiRec in astrings.inc
TStrRec = record
{$ifdef ISFPC27}
codePage: Word;
codePage: TSystemCodePage;
elemSize: Word;
{$endif}
{$ifdef CPU64}
_Padding: LongInt;
_Padding: DWord;
{$endif}
refCnt: SizeInt;
length: SizeInt;
{$else FPC}
TStrRec = packed record
{$ifdef UNICODE}
{$ifdef CPU64}
/// padding bytes for 16 byte alignment of the header
@@ -21195,7 +21192,7 @@ function Deref(Info: PTypeInfoStored): PTypeInfo;
{$ifdef HASCODEPAGE}
procedure FastSetStringCP(var s; p: pointer; len, codepage: PtrInt);
var r: PAnsiChar; // s may = p -> stand-alone variable
sr: PStrRec; // stand-alone to use register
sr: PStrRec; // local copy of r, to use register
begin
if len>0 then begin
GetMem(r,len+(STRRECSIZE+2));
@@ -21216,9 +21213,9 @@ procedure FastSetStringCP(var s; p: pointer; len, codepage: PtrInt);
{$ifdef FPC}Finalize(RawByteString(s)){$else}RawByteString(s) := ''{$endif};
end;
procedure FastSetString(var s; p: pointer; len: PtrInt);
var r: PAnsiChar; // s may = p -> stand-alone variable
sr: PStrRec; // stand-alone to use register
procedure FastSetString(var s: RawUTF8; p: pointer; len: PtrInt);
var r: PAnsiChar;
sr: PStrRec;
begin
if len>0 then begin
GetMem(r,len+(STRRECSIZE+2));
@@ -21232,18 +21229,18 @@ procedure FastSetString(var s; p: pointer; len: PtrInt);
r := pointer(sr);
if p<>nil then
MoveFast(p^,sr^,len);
{$ifdef FPC}Finalize(RawByteString(s)){$else}RawByteString(s) := ''{$endif};
{$ifdef FPC}Finalize(s){$else}s := ''{$endif};
pointer(s) := r;
end
else
{$ifdef FPC}Finalize(RawByteString(s)){$else}RawByteString(s) := ''{$endif};
{$ifdef FPC}Finalize(s){$else}s := ''{$endif};
end;
{$else}
procedure FastSetStringCP(var s; p: pointer; len, codepage: PtrInt);
begin
SetString(RawByteString(s),PAnsiChar(p),len);
end;
procedure FastSetString(var s; p: pointer; len: PtrInt);
procedure FastSetString(var s: RawUTF8; p: pointer; len: PtrInt);
begin
SetString(RawByteString(s),PAnsiChar(p),len);
end;
@@ -43028,7 +43025,7 @@ procedure RawUTF8ToVariant(Txt: PUTF8Char; TxtLen: integer; var Value: variant);
VType := varString;
VAny := nil; // avoid GPF below when assigning a string variable to VAny
end;
FastSetString(VString,Txt,TxtLen);
FastSetString(RawUTF8(VString),Txt,TxtLen);
end;
end;
@@ -43244,7 +43241,7 @@ function VariantLoad(var Value: variant; Source: PAnsiChar;
tmp.Len := FromVarUInt32(PByte(Source));
case VType of
varString:
FastSetString(VString,Source,tmp.Len); // explicit RawUTF8
FastSetString(RawUTF8(VString),Source,tmp.Len); // explicit RawUTF8
varOleStr:
SetString(WideString(VAny),PWideChar(Source),tmp.Len shr 1);
{$ifdef HASVARUSTRING}
@@ -43906,7 +43903,7 @@ procedure GetVariantFromJSON(JSON: PUTF8Char; wasString: Boolean; var Value: var
// found no numerical value -> return a string in the expected format
VType := varString;
VString := nil; // avoid GPF below when assigning a string variable to VAny
FastSetString(VString,JSON,StrLen(JSON));
FastSetString(RawUTF8(VString),JSON,StrLen(JSON));
end;
end;
@@ -54302,7 +54299,7 @@ procedure GetJSONItemAsRawJSON(var P: PUTF8Char; var result: RawJSON;
P := GotoEndJSONItem(B);
if P=nil then
exit;
FastSetString(result,B,P-B);
FastSetString(RawUTF8(result),B,P-B);
while (P^<=' ') and (P^<>#0) do inc(P);
if EndOfObject<>nil then
EndOfObject^ := P^;
@@ -1 +1 @@
'1.18.4726'
'1.18.4727'
@@ -27,7 +27,7 @@
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<Libraries Value="static\$(TargetCPU)-$(TargetOS)"/>
<UnitOutputDirectory Value="SQLite3\fpc\x86_64-win64"/>
<UnitOutputDirectory Value="SQLite3\fpc\lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
@@ -80,7 +80,7 @@
</Target>
<SearchPaths>
<Libraries Value="static\$(TargetCPU)-$(TargetOS)"/>
<UnitOutputDirectory Value="SQLite3\fpc\i386-win32"/>
<UnitOutputDirectory Value="SQLite3\fpc\lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>

0 comments on commit c727eaa

Please sign in to comment.