+ added method TBits.CopyBits for fast copying

git-svn-id: trunk@40524 -
This commit is contained in:
nickysn 2018-12-11 15:52:09 +00:00
parent c283775b73
commit da5868b668
4 changed files with 61 additions and 0 deletions

1
.gitattributes vendored
View File

@ -14135,6 +14135,7 @@ tests/test/units/classes/tbytesstreamtest.pp svneol=native#text/pascal
tests/test/units/classes/tmakeobjinst.pp svneol=native#text/plain
tests/test/units/classes/tsetstream.pp svneol=native#text/plain
tests/test/units/classes/tstringlistexchange.pp svneol=native#text/pascal
tests/test/units/classes/ttbits.pp svneol=native#text/pascal
tests/test/units/classes/tvclcomobject.pp svneol=native#text/plain
tests/test/units/cpu/tcpu1.pp svneol=native#text/pascal
tests/test/units/crt/tcrt.pp svneol=native#text/plain

View File

@ -173,6 +173,12 @@ begin
result := (FBits^[n] and (longint(1) shl (bit and MASK))) <> 0;
end;
procedure TBits.CopyBits(BitSet : TBits);
begin
setSize(bitset.Size);
Move(bitset.FBits^,FBits^,FSize*SizeOf(cardinal));
end;
procedure TBits.andbits(bitset : TBits);
var
n : longint;

View File

@ -400,6 +400,7 @@ type
procedure SetOn(Bit : longint);
procedure Clear(Bit : longint);
procedure Clearall;
procedure CopyBits(BitSet : TBits);
procedure AndBits(BitSet : TBits);
procedure OrBits(BitSet : TBits);
procedure XorBits(BitSet : TBits);

View File

@ -0,0 +1,53 @@
program ttbits;
{$MODE objfpc}{$H+}
uses
Classes;
procedure Fail;
begin
Writeln('Err!');
Halt(1);
end;
procedure FillWithRandom(b: TBits);
var
I: Integer;
begin
for I := 0 to b.Size - 1 do
b[I] := Random(2) <> 0;
end;
procedure TestCopyBits;
const
NumTests = 100;
MaxBits = 200;
var
b1: TBits = nil;
b2: TBits = nil;
I: Integer;
begin
try
b1 := TBits.Create;
b2 := TBits.Create;
for I := 1 to NumTests do
begin
b1.Size := Random(MaxBits);
FillWithRandom(b1);
b2.CopyBits(b1);
if not b1.Equals(b2) then
Fail;
if not b2.Equals(b1) then
Fail;
end;
finally
b1.Free;
b2.Free;
end;
end;
begin
TestCopyBits;
Writeln('Ok!');
end.