diff options
author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-02-13 21:29:23 +0000 |
---|---|---|
committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-02-13 21:29:23 +0000 |
commit | 21f6f2fbac99fa18848663d07ffddc903ee39adb (patch) | |
tree | d85d9413b6532ce78125b25dd8d7f9757ba3d4ad /packages/fcl-stl | |
parent | 8d2f6550fe1952fea78459509362c437792664d8 (diff) | |
download | fpc-21f6f2fbac99fa18848663d07ffddc903ee39adb.tar.gz |
* fix TVector.Reserve after IncreaseCapacity changes, resolves #36698
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@44167 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-stl')
-rw-r--r-- | packages/fcl-stl/src/gvector.pp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/packages/fcl-stl/src/gvector.pp b/packages/fcl-stl/src/gvector.pp index 834045c622..9724f1248b 100644 --- a/packages/fcl-stl/src/gvector.pp +++ b/packages/fcl-stl/src/gvector.pp @@ -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); |