Переглянути джерело

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

# revisions: 44225

git-svn-id: branches/fixes_3_2@44307 -

marco 5 роки тому
батько
коміт
6d1a81ffde

+ 1 - 0
.gitattributes

@@ -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

+ 13 - 7
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);

+ 12 - 0
rtl/objpas/classes/streams.inc

@@ -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 - 0
tests/webtbs/tw36698.pp

@@ -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.