Skip to content
Permalink
Browse files

slight optimization of bit-level processing - no functional change

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed May 17, 2019
1 parent 0822a40 commit 727381e0ac6058633179383a870217db6d0ba884
Showing with 34 additions and 19 deletions.
  1. +7 −7 SQLite3/mORMotToolBar.pas
  2. +2 −2 SQLite3/mORMotUI.pas
  3. +1 −1 SQLite3/mORMotUIEdit.pas
  4. +2 −2 SQLite3/mORMotUIOptions.pas
  5. +11 −2 SynCommons.pas
  6. +8 −2 SynEcc.pas
  7. +1 −1 SynMongoDB.pas
  8. +1 −1 SynPdf.pas
  9. +1 −1 SynopseCommit.inc
@@ -1079,7 +1079,7 @@ function TSQLLister.SetToolBar(const aToolBarName: string; const aActions;
GB := TSynToolButton(result.Components[iGB]);
if isActionButton(GB)<>0 then begin
img := GB.ImageIndex;
EN := GetBit(aActions,img+1);
EN := GetBitPtr(@aActions,img+1);
GB.Enabled := EN; // enable or disable buttons
for iM := 0 to fMenu.Items.Count-1 do
with fMenu.Items[iM] do
@@ -1094,7 +1094,7 @@ function TSQLLister.SetToolBar(const aToolBarName: string; const aActions;
// no Toolbar: create one with its buttons; also create associated popup menu
EN := false;
for A := 0 to fActionMax do
if GetBit(aActions,A) then begin
if GetBitPtr(@aActions,A) then begin
EN := true;
break;
end;
@@ -1124,10 +1124,10 @@ function TSQLLister.SetToolBar(const aToolBarName: string; const aActions;
end;
for iAction := fActionMax downto 0 do begin // TToolBar adds at 1st position
{$endif}
if GetBit(aActions,iAction) then // is this enumerate value inside aActions?
if GetBitPtr(@aActions,iAction) then // is this enumerate value inside aActions?
with result.CreateToolButton(ActionButtonClick,iAction,1,ActionNames[iAction],
ActionHints,fShortCutUsed,60,ImageList32) do begin
if GetBit(ActionIsNotButton,iAction) then
if GetBitPtr(@ActionIsNotButton,iAction) then
Style := bsCheck;
// create associated sub menu entry
if Style<>bsCheck then begin
@@ -1655,7 +1655,7 @@ function AddReportMenu(const Caption: string): TMenuItem;
AddReportMenu('-'); // separator
P := @FReportPopupParams^.NameList;
for i := 0 to FReportPopupParams^.MaxValue do begin
if GetBit(FReportPopupParamsEnabled^,i) then
if GetBitPtr(FReportPopupParamsEnabled,i) then
with AddReportMenu(Table.CaptionNameFromRTTI(P)) do
Checked := (FReportPopupValues[i]<>nil) and FReportPopupValues[i]^;
inc(PByte(P),ord(P^[0])+1); // next enumeration item
@@ -1727,7 +1727,7 @@ function TSQLCustomToolBar.AddToolBar(const ToolBarName: string;
result := Page.CreateToolBar else begin
result := nil;
for iAction := 0 to ActionsEnum^.MaxValue do
if GetBit(ActionsBits^,iAction) then begin
if GetBitPtr(ActionsBits,iAction) then begin
result := Page.CreateToolBar;
break;
end;
@@ -1757,7 +1757,7 @@ function TSQLCustomToolBar.AddToolBar(const ToolBarName: string;
end; // TToolBar adds at 1st position -> downto
for iAction := ActionsEnum^.MaxValue downto 0 do begin
{$endif}
if (ActionsBits=nil) or GetBit(ActionsBits^,iAction) then
if (ActionsBits=nil) or GetBitPtr(ActionsBits,iAction) then
Buttons[iAction] := result.CreateToolButton(ButtonClick,iAction,
ImageListFirstIndex,ActionNames[iAction],ActionHints,ShortCutUsed,
ButtonWidth,ImageList);
@@ -1790,7 +1790,7 @@ function TSQLTableToGrid.GetMarked(RowIndex: integer): boolean;
if (self=nil) or (fMarked=nil) or
(cardinal(RowIndex)>=cardinal(length(fMarked)shl 3)) then
result := false else
result := GetBit(fMarked[0],RowIndex);
result := GetBitPtr(pointer(fMarked),RowIndex);
end;

procedure TSQLTableToGrid.SetMarked(RowIndex: integer;
@@ -1882,7 +1882,7 @@ function TSQLTableToGrid.GetMarkAvailable: boolean;
if not result then
exit;
for i := 0 to Table.RowCount-1 do // very any bit is realy set
if GetBit(fMarked[0],i) then
if GetBitPtr(pointer(fMarked),i) then
exit;
result := false;
end;
@@ -447,7 +447,7 @@ procedure TRecordEditForm.SetRecord(aClient: TSQLRestClient;
Hint := aHint;
ShowHint := True;
end;
Checked := GetBit(Sets,j);
Checked := GetBitPtr(@Sets,j);
Enabled := Group.Enabled;
Tag := i+1+(j+1) shl 8; // for BtnSaveClick() event
inc(PtrInt(EP),ord(EP^[0])+1); // next enumeration item
@@ -368,7 +368,7 @@ procedure TOptionsForm.AddToolbars(Scroll: TScrollBox; const aToolbarName: strin
E := aEnum^.EnumBaseType;
assert(E^.MaxValue<64); // Value is a Int64 (i.e. max 64 actions)
for A := 0 to E^.MaxValue do
if (aActionsBits=nil) or GetBit64(aActionsBits^,A) then begin
if (aActionsBits=nil) or GetBitPtr(aActionsBits,A) then begin
with TCheckBox.Create(Scroll) do begin
Parent := Scroll;
Hint := GetCSVItemString(pointer(aActionHints),A,#13);
@@ -377,7 +377,7 @@ procedure TOptionsForm.AddToolbars(Scroll: TScrollBox; const aToolbarName: strin
SetBounds(64,Scroll.Tag,W,16);
V := aProp^.GetInt64Value(Obj);
fAddToolbar := fAddToolbar+AnsiChar(A); // every char is a bit index
Checked := GetBit64(V,A);
Checked := GetBitPtr(@V,A);
Tag := PtrInt(aProp); // for BtnSaveClick() event
end;
Scroll.Tag := Scroll.Tag+16;
InterningHasher: THasher;

/// retrieve a particular bit status from a bit array
// - this function can't be inlined, whereas GetBitPtr() function can
function GetBit(const Bits; aIndex: PtrInt): boolean;

/// set a particular bit into a bit array
// - this function can't be inlined, whereas SetBitPtr() function can
procedure SetBit(var Bits; aIndex: PtrInt);

/// unset/clear a particular bit into a bit array
// - this function can't be inlined, whereas UnSetBitPtr() function can
procedure UnSetBit(var Bits; aIndex: PtrInt);

/// retrieve a particular bit status from a bit array
// - GetBit() can't be inlined, whereas this pointer-oriented function can
function GetBitPtr(Bits: pointer; aIndex: PtrInt): boolean;
{$ifdef HASINLINE}inline;{$endif}

/// set a particular bit into a bit array
// - SetBit() can't be inlined, whereas this pointer-oriented function can
procedure SetBitPtr(Bits: pointer; aIndex: PtrInt);
{$ifdef HASINLINE}inline;{$endif}

/// unset/clear a particular bit into a bit array
// - UnSetBit() can't be inlined, whereas this pointer-oriented function can
procedure UnSetBitPtr(Bits: pointer; aIndex: PtrInt);
{$ifdef HASINLINE}inline;{$endif}

function GotoNextVarInt(Source: PByte): pointer;
begin
if Source<>nil then begin
while Source^>$7f do inc(Source);
if Source^>$7f then
repeat
inc(Source)
until Source^<=$7f;
inc(Source);
end;
result := Source;
if not(EndOfObject in [',','}']) then
exit; // invalid item separator
for i := 0 to n do
if IdemPropNameU(Names[i],name,namelen) then begin
if (Values[i].Value=nil) and IdemPropNameU(Names[i],name,namelen) then begin
Values[i].Value := value;
Values[i].ValueLen := valuelen;
break;
@@ -2087,6 +2087,12 @@ function _isZero(const VLI: TVLI): boolean; {$ifdef HASINLINE}inline;{$endif}
result := (VLI[0]=0) and (VLI[1]=0) and (VLI[2]=0) and (VLI[3]=0);
end;

function _equals(const Left, Right: TVLI): boolean; {$ifdef HASINLINE}inline;{$endif}
begin
result := (Left[0]=Right[0]) and (Left[1]=Right[1]) and (Left[2]=Right[2]) and
(Left[3]=Right[3]);
end;

// counts the number of bits required for VLI
function _numBits(const VLI: TVLI): integer;
var i: integer;
@@ -2814,7 +2820,7 @@ function ecc_make_key_pas(out PublicKey: TECCPublicKey; out PrivateKey: TECCPriv
TAESPRNG.Fill(THash256(PrivateK));
if tries >= MAX_TRIES then
exit;
if _isZero(PrivateK) or (_cmp(PrivateK, _1) = 0) or (_cmp(PrivateK, _11) = 0) then
if _isZero(PrivateK) or _equals(PrivateK, _1) or _equals(PrivateK, _11) then
continue;
// Make sure the private key is in the range [1, n-1]
// For the supported curves, n is always large enough that we only need
@@ -2931,7 +2937,7 @@ function ecdsa_sign_pas(const PrivateKey: TECCPrivateKey; const Hash: TEccHash;
TAESPRNG.Fill(THash256(k));
if Tries >= MAX_TRIES then
exit;
if _isZero(k) or (_cmp(k, _1) = 0) or (_cmp(k, _11) = 0) then
if _isZero(k) or _equals(k, _1) or _equals(k, _11) then
continue;
if _cmp(Curve_N_32, k) <> 1 then
_sub(k, k, Curve_N_32);
@@ -3884,9 +3884,9 @@ procedure InitBSONObjectIDComputeNew;
procedure TBSONObjectID.ComputeNew;
var now, count: cardinal;
begin
now := UnixTimeUTC; // fast API call (no need of cache)
with GlobalBSONObjectID do begin
EnterCriticalSection(Section);
now := UnixTimeUTC; // fast API call (no need of cache)
if now>LastCreateTime then begin
LastCreateTime := now;
count := Default.Counter; // reset
@@ -8791,7 +8791,7 @@ constructor TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType);
// (from http://www.microsoft.com/typography/OTSPEC/head.htm)
fUnitsPerEmShr := 0; // fastest integer div for width calculating
for i := 14 downto 4 do
if GetBit(head^.UnitsPerEm,i) then begin
if GetBitPtr(@head^.UnitsPerEm,i) then begin
fUnitsPerEmShr := i;
break;
end;
@@ -1 +1 @@
'1.18.5221'
'1.18.5222'

0 comments on commit 727381e

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