mORMot and Open Source friends
Check-in [56f226240d]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:{5815} faster StrLenPas() and BufferLineLength()
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 56f226240df88162d68c9230f3d703a3d8bc778e
User & Date: ab 2020-03-12 20:50:11
Context
2020-03-12
20:50
{5816} slightly optimized /root/timestamp URI endpoint check-in: ef1845e4b0 user: ab tags: trunk
20:50
{5815} faster StrLenPas() and BufferLineLength() check-in: 56f226240d user: ab tags: trunk
20:49
{5814} refactored GotoNextLine() for better performance and no compiler complain check-in: 9248eaeaa1 user: ab tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SynCommons.pas.

23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986


23987
23988
23989
23990
23991
23992
23993
.....
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
.....
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057

33058
33059
33060
33061
33062
33063
33064
33065

33066
33067
33068
33069
33070
33071
33072
.....
58557
58558
58559
58560
58561
58562
58563
58564
58565
58566
58567
58568
58569
58570
58571
        result := C1-C2;
      end else
      result := 1 else  // Str2=''
    result := -1;     // Str1=''
end;

function StrLenPas(S: pointer): PtrInt;
begin
  result := 0;
  if S<>nil then
  while true do
    if PAnsiChar(S)[result+0]<>#0 then
    if PAnsiChar(S)[result+1]<>#0 then
    if PAnsiChar(S)[result+2]<>#0 then
    if PAnsiChar(S)[result+3]<>#0 then
      inc(result,4) else begin
      inc(result,3);
      exit;
    end else begin
      inc(result,2);
      exit;
    end else begin
      inc(result);
      exit;
    end else
      exit;


end;

function StrCompFast(Str1, Str2: pointer): PtrInt;
var c: byte;
begin
  if Str1<>Str2 then
  if Str1<>nil then
................................................................................
    if result then begin
      inc(source,Length(searchUp));
      GetNextItem(source,Sep,Item);
    end;
  end;
end;

{$ifdef FPC}{$push}{$endif}
{$WARNINGS OFF} // some Delphi compilers do not analyze well code below
function GotoNextLine(source: PUTF8Char): PUTF8Char;
label
  _0, _1, _2, _3; // ugly but faster
begin
  result := source;
  if source<>nil then
    repeat
................................................................................
        jc      @fail
        add     rax, r8
{$ifdef MSWINDOWS}
        pop     rdi
        pop     rsi
{$endif}
end;
{$else} {$ifdef FPC}inline;{$endif}
var c: cardinal;
begin
  result := 0;
  dec(PtrUInt(TextEnd),PtrUInt(Text)); // compute TextLen
  if TextEnd<>nil then
    repeat
      c := ord(Text[result]);
      if c>13 then begin
        inc(result);
        if PtrUInt(result)>=PtrUInt(TextEnd) then
          break;

        continue;
      end;
      if (c=10) or (c=13) then
        break;
      inc(result);
      if PtrUInt(result)>=PtrUInt(TextEnd) then
        break;
    until false;

end;
{$endif CPUX64}

function GetLineSize(P, PEnd: PUTF8Char): PtrUInt;
var c: byte;
begin
  {$ifdef CPUX64}
................................................................................
var i: PtrInt; // use a temp variable to make oldest Delphi happy :(
begin
  result := -1;
  if self<>nil then begin
    fSafe.Lock;
    try
      for i := aFirstIndex to fCount-1 do
        if PosEx(aText,fValue[result])>0 then begin
          result := i;
          exit;
        end;
    finally
      fSafe.UnLock;
    end;
  end;






|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>







 







<
<







 







|
<

|
<
<
|
<
<
|
|
<
>

<
<
|
<
<
<
|
>







 







|







23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
.....
32936
32937
32938
32939
32940
32941
32942


32943
32944
32945
32946
32947
32948
32949
.....
33039
33040
33041
33042
33043
33044
33045
33046

33047
33048


33049


33050
33051

33052
33053


33054



33055
33056
33057
33058
33059
33060
33061
33062
33063
.....
58548
58549
58550
58551
58552
58553
58554
58555
58556
58557
58558
58559
58560
58561
58562
        result := C1-C2;
      end else
      result := 1 else  // Str2=''
    result := -1;     // Str1=''
end;

function StrLenPas(S: pointer): PtrInt;
label
  _0, _1, _2, _3; // ugly but faster
begin
  result := PtrUInt(S);
  if S<>nil then begin
    while true do
      if PAnsiChar(result)[0]=#0 then
        goto _0
      else if PAnsiChar(result)[1]=#0 then
        goto _1
      else if PAnsiChar(result)[2]=#0 then
        goto _2
      else if PAnsiChar(result)[3]=#0 then
        goto _3
      else
        inc(result, 4);
_3: inc(result);
_2: inc(result);
_1: inc(result);
_0: dec(result,PtrUInt(S)); // return length
  end;
end;

function StrCompFast(Str1, Str2: pointer): PtrInt;
var c: byte;
begin
  if Str1<>Str2 then
  if Str1<>nil then
................................................................................
    if result then begin
      inc(source,Length(searchUp));
      GetNextItem(source,Sep,Item);
    end;
  end;
end;



function GotoNextLine(source: PUTF8Char): PUTF8Char;
label
  _0, _1, _2, _3; // ugly but faster
begin
  result := source;
  if source<>nil then
    repeat
................................................................................
        jc      @fail
        add     rax, r8
{$ifdef MSWINDOWS}
        pop     rdi
        pop     rsi
{$endif}
end;
{$else}

begin
  result := PtrUInt(Text)-1;


  repeat


    inc(result);
    if PtrUInt(result)<PtrUInt(TextEnd) then

      if (PByte(result)^>13) or ((PByte(result)^<>10) and (PByte(result)^<>13)) then
        continue;


    break;



  until false;
  dec(result,PtrInt(Text)); // returns length
end;
{$endif CPUX64}

function GetLineSize(P, PEnd: PUTF8Char): PtrUInt;
var c: byte;
begin
  {$ifdef CPUX64}
................................................................................
var i: PtrInt; // use a temp variable to make oldest Delphi happy :(
begin
  result := -1;
  if self<>nil then begin
    fSafe.Lock;
    try
      for i := aFirstIndex to fCount-1 do
        if PosEx(aText,fValue[i])>0 then begin
          result := i;
          exit;
        end;
    finally
      fSafe.UnLock;
    end;
  end;

Changes to SynopseCommit.inc.

1
'1.18.5814'
|
1
'1.18.5815'