--- Recording mergeinfo for merge of r44225 into '.':

G   .

# revisions: 44225

git-svn-id: branches/fixes_3_2@44307 -
This commit is contained in:
marco 2020-03-17 09:36:47 +00:00
parent 0710825bda
commit 6d1a81ffde
4 changed files with 67 additions and 7 deletions

1
.gitattributes vendored
View File

@ -17616,6 +17616,7 @@ tests/webtbs/tw36544b.pp svneol=native#text/pascal
tests/webtbs/tw3661.pp svneol=native#text/plain
tests/webtbs/tw3666.pp svneol=native#text/plain
tests/webtbs/tw3669.pp svneol=native#text/plain
tests/webtbs/tw36698.pp -text svneol=native#text/pascal
tests/webtbs/tw3676.pp svneol=native#text/plain
tests/webtbs/tw3681.pp svneol=native#text/plain
tests/webtbs/tw3683.pp svneol=native#text/plain

View File

@ -33,7 +33,8 @@ type
procedure SetValue(Position: SizeUInt; const Value: T); inline;
function GetValue(Position: SizeUInt): T; inline;
function GetMutable(Position: SizeUInt): PT; inline;
procedure IncreaseCapacity; inline;
function NewCapacity: SizeUInt;
procedure IncreaseCapacity;
const
// todo: move these constants to implementation when
@ -162,7 +163,7 @@ begin
inc(FDataSize);
end;
procedure TVector.IncreaseCapacity();
function TVector.NewCapacity: SizeUInt;
const
// if size is small, multiply by 2;
// if size bigger but <256M, inc by 1/8*size;
@ -174,15 +175,20 @@ var
begin
DataSize:=FCapacity*SizeOf(T);
if FCapacity=0 then
FCapacity:=4
Result:=4
else
if DataSize<cSizeSmall then
FCapacity:=FCapacity*2
Result:=FCapacity*2
else
if DataSize<cSizeBig then
FCapacity:=FCapacity+FCapacity div 8
Result:=FCapacity+FCapacity div 8
else
FCapacity:=FCapacity+FCapacity div 16;
Result:=FCapacity+FCapacity div 16;
end;
procedure TVector.IncreaseCapacity();
begin
FCapacity:=NewCapacity;
SetLength(FData, FCapacity);
end;
@ -239,7 +245,7 @@ procedure TVector.Reserve(Num: SizeUInt);
begin
if(Num < FCapacity) then
exit
else if(Num <= 2*FCapacity) then
else if (Num <= NewCapacity) then
IncreaseCapacity
else begin
SetLength(FData, Num);

View File

@ -562,9 +562,21 @@ begin
If (THandle(FHandle)=feInvalidHandle) then
If Mode=fmcreate then
begin
{$if declared(GetLastOSError)}
raise EFCreateError.createfmt(SFCreateErrorEx,[AFileName, SysErrorMessage(GetLastOSError)])
{$else}
raise EFCreateError.createfmt(SFCreateError,[AFileName])
{$endif}
end
else
begin
{$if declared(GetLastOSError)}
raise EFOpenError.Createfmt(SFOpenErrorEx,[AFilename, SysErrorMessage(GetLastOSError)]);
{$else}
raise EFOpenError.Createfmt(SFOpenError,[AFilename]);
{$endif}
end;
end;

41
tests/webtbs/tw36698.pp Normal file
View File

@ -0,0 +1,41 @@
program map_test;
{$mode objfpc}
uses
SysUtils, ghashmap;
const
TestSize = 270000;
type
THash = class
class function Hash(aValue: Integer; n: SizeUInt): SizeUInt; static;
end;
TMap = specialize THashmap<Integer, Integer, THash>;
class function THash.Hash(aValue: Integer; n: SizeUInt): SizeUInt;
begin
aValue := aValue xor aValue shr 20 xor aValue shr 12;
Result := SizeUInt(aValue xor aValue shr 7 xor aValue shr 4) and (n-1);
end;
procedure Test;
var
Map: TMap;
I: Integer;
begin
Map := TMap.Create;
try
for I := 1 to TestSize do
Map.Insert(I, I);
finally
Map.Free;
end;
end;
begin
Test;
end.