Skip to content
Permalink
Browse files

new GetBitPtr/SetBitPtr/UnsetBitPtr functions for proper inlining

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Apr 1, 2019
1 parent ef1b690 commit ae85105151e810c093953b496f600d14e8bf91fe
Showing with 179 additions and 165 deletions.
  1. +21 −21 SQLite3/mORMot.pas
  2. +2 −2 SQLite3/mORMotSQLite3.pas
  3. +3 −3 SQLite3/mORMotUI.pas
  4. +141 −127 SynCommons.pas
  5. +1 −1 SynDBSQLite3.pas
  6. +8 −8 SynEcc.pas
  7. +2 −2 SynTable.pas
  8. +1 −1 SynopseCommit.inc
R := @fResults[FieldCount];
j := FieldCount;
for i := 1 to fRowCount do begin
if GetBit(Bits,i-1) then begin
if GetBitPtr(@Bits,i-1) then begin
if fIDColumn<>nil then
fIDColumn[n] := oldIDColumn[i];
MoveFast(oldResults[j],R^,FieldCount*SizeOf(PUTF8Char));
// put unmarked IDs
j := FieldCount;
for i := 1 to fRowCount do begin
if not GetBit(Bits,i-1) then begin
if not GetBitPtr(@Bits,i-1) then begin
if fIDColumn<>nil then
fIDColumn[n] := oldIDColumn[i];
MoveFast(oldResults[j],R^,FieldCount*SizeOf(PUTF8Char));
// recalcultate Bits[]
{$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,0);
for i := 0 to nSet-1 do
SetBit(Bits,i); // slow but accurate
SetBitPtr(@Bits,i); // slow but accurate
end;

function TSQLTable.IDColumnHide: boolean;
n := 0;
if Assigned(fIDColumn) then begin
for i := 1 to fRowCount do
if GetBit(Bits,i-1) then begin
if GetBitPtr(@Bits,i-1) then begin
IDs[n] := GetInt64(fIDColumn[i]); // get hidden ID column UTF-8 content
inc(n);
end;
end else begin
inc(FID,FieldCount); // [i*FieldCount+FID] = [(i+1)*FieldCount+FID] below
for i := 0 to fRowCount-1 do
if GetBit(Bits,i) then begin
if GetBitPtr(@Bits,i) then begin
IDs[n] := GetInt64(fResults[i*FieldCount+FID]); // get ID column UTF-8 content
inc(n);
end;
IDn: integer;
// AllID: : TIDDynArray;
begin
if length(IDs)=RowCount then begin // all selected -> all bits set to 1
{$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(RowCount shr 3)+1,255);
if length(IDs)=fRowCount then begin // all selected -> all bits set to 1
{$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,255);
exit;
end;
{$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(RowCount shr 3)+1,0);
{$ifdef FPC}FillChar{$else}FillCharFast{$endif}(Bits,(fRowCount shr 3)+1,0);
if IDs=nil then
exit; // no selected -> all bits left to 0
// we sort IDs to use FastFindIntegerSorted() and its O(log(n)) binary search
end else
FID := 0; // make compiler happy
if Assigned(fIDColumn) then begin
for i := 1 to RowCount do
for i := 1 to fRowCount do
if FastFindInt64Sorted(ID,IDn,GetInt64(fIDColumn[i]))>=0 then
SetBit(Bits,i-1);
SetBitPtr(@Bits,i-1);
end else begin
U := @fResults[FID+FieldCount]; // U^ = ID column UTF-8 content
for i := 0 to RowCount-1 do begin
for i := 0 to fRowCount-1 do begin
if FastFindInt64Sorted(ID,IDn,GetInt64(U^))>=0 then
SetBit(Bits,i);
SetBitPtr(@Bits,i);
inc(U,FieldCount);
end;
end;
new[f] := i;
end;
ndx := FieldCount;
for i := 1 to RowCount do begin // merge data
for i := 1 to fRowCount do begin // merge data
k := From.SearchFieldSorted(fResults[ndx+dk],fk);
if k>0 then begin
k := k*From.FieldCount;
PS: PShortString;
begin
W.Add('[');
if FullSetsAsStar and (MaxValue in [1..31]) and GetAllBits(Value,MaxValue+1) then
if FullSetsAsStar and GetAllBits(Value,MaxValue+1) then
W.AddShort('"*"') else begin
PS := @NameList;
for j := MinValue to MaxValue do begin
if GetBit(Value,j) then begin
if GetBitPtr(@Value,j) then begin
W.Add('"');
if twoTrimLeftEnumSets in W.CustomOptions then
W.AddTrimLeftLowerCase(PS) else
arr: TDocVariantData;
begin
arr.InitFast;
if FullSetsAsStar and (MaxValue in [1..31]) and GetAllBits(Value,MaxValue+1) then
if FullSetsAsStar and GetAllBits(Value,MaxValue+1) then
arr.AddItem('*') else begin
PS := @NameList;
for j := MinValue to MaxValue do begin
if GetBit(Value,j) then
if GetBitPtr(@Value,j) then
arr.AddItem(PS^);
inc(PByte(PS),ord(PS^[0])+1); // next item
end;
V := @NameList;
for i := MinValue to MaxValue do begin
if (UsedValuesBits=nil) or
GetBit(UsedValuesBits^,i) then begin
GetBitPtr(UsedValuesBits,i) then begin
L := ord(V^[0]);
P := @V^[1];
while (L>0) and (P^ in ['a'..'z']) do begin // ignore left lowercase chars
T := MultiFieldValues(Table,FieldName,FormatSQLWhere,BoundsSQLWhere);
if T<>nil then
try
res.InitFast(T.RowCount,dvArray);
res.SetCount(T.RowCount);
for row := 1 to T.RowCount do
res.InitFast(T.fRowCount,dvArray);
res.SetCount(T.fRowCount);
for row := 1 to T.fRowCount do
T.GetAsVariant(row,0,res.Values[row-1],false,false,false,JSON_OPTIONS_FAST);
finally
T.Free;
@@ -2048,7 +2048,7 @@ procedure TSQLRestServerDB.InternalBatchStop;
SetLength(Values,MAX_PARAMS);
for f := 0 to fieldCount-1 do
if Decode.FieldTypeApproximation[f]=ftaNull then
SetBit(ValuesNull[0],valuesCount+f) else
SetBitPtr(pointer(ValuesNull),valuesCount+f) else
Values[valuesCount+f] := Decode.FieldValues[f];
inc(ValuesCount,fieldCount);
inc(rowCount);
@@ -2065,7 +2065,7 @@ procedure TSQLRestServerDB.InternalBatchStop;
PrepareStatement((rowCount<5) or (valuesCount+fieldCount>MAX_PARAMS));
prop := 0;
for f := 0 to valuesCount-1 do begin
if GetBit(ValuesNull[0],f) then
if GetBitPtr(pointer(ValuesNull),f) then
fStatement^.BindNull(f+1) else
case Types[prop] of
ftInt64:
@@ -241,7 +241,7 @@ TSQLTableToGrid = class(TComponent)
{$else}
fOnDrawCellBackground: TDrawCellEvent;
{$endif}
fMarked: array of byte;
fMarked: TByteDynArray;
fMarkAllowed: boolean;
fMouseDownMarkedValue: (markNone,markOn,markOff);
fTruncAsHint: Boolean;
@@ -1804,8 +1804,8 @@ procedure TSQLTableToGrid.SetMarked(RowIndex: integer;
if length(fMarked)<n then // need to allocate/expand fMarked[] array?
SetLength(fMarked,n); // initializes all expanded bytes to 0
if Value then
SetBit(fMarked[0],RowIndex) else
UnSetBit(fMarked[0],RowIndex)
SetBitPtr(pointer(fMarked),RowIndex) else
UnSetBitPtr(pointer(fMarked),RowIndex)
end;

procedure TSQLTableToGrid.SetMark(aAction: TSQLAction);
Oops, something went wrong.

0 comments on commit ae85105

Please sign in to comment.
You can’t perform that action at this time.