Pārlūkot izejas kodu

Fix for Mantis #23909.

gvector.pp, TVector.TVectorEnumerator:
  * the size of a vector is of type SizeUInt which is LongWord on 32 bit systems and QWord on 64 bit systems and which is in both cases not the same as Integer which is LongInt
  + add a boolean property to detect whether the first call to MoveNext was done
  * check in MoveNext whether the first call was done and return approbiate results
gvector.pp, TVector:
  + declare GetEnumerator as inline as well

git-svn-id: trunk@23645 -
svenbarth 12 gadi atpakaļ
vecāks
revīzija
c21b34daf1
1 mainītis faili ar 12 papildinājumiem un 7 dzēšanām
  1. 12 7
      packages/fcl-stl/src/gvector.pp

+ 12 - 7
packages/fcl-stl/src/gvector.pp

@@ -45,10 +45,11 @@ type
     TVectorEnumerator = class
     TVectorEnumerator = class
     private
     private
       FVector: TVector;
       FVector: TVector;
-      FPosition: Integer;
+      FPosition: SizeUInt;
+      FFirstDone: Boolean;
+      function GetCurrent: T; inline;
     public
     public
       constructor Create(AVector: TVector);
       constructor Create(AVector: TVector);
-      function GetCurrent: T; inline;
       function MoveNext: Boolean; inline;
       function MoveNext: Boolean; inline;
       property Current: T read GetCurrent;
       property Current: T read GetCurrent;
     end;
     end;
@@ -67,7 +68,7 @@ type
     procedure Reserve(Num: SizeUInt); inline;
     procedure Reserve(Num: SizeUInt); inline;
     procedure Resize(Num: SizeUInt); inline;
     procedure Resize(Num: SizeUInt); inline;
 
 
-    function GetEnumerator: TVectorEnumerator;
+    function GetEnumerator: TVectorEnumerator; inline;
 
 
     property Items[i : SizeUInt]: T read getValue write setValue; default;
     property Items[i : SizeUInt]: T read getValue write setValue; default;
     property Mutable[i : SizeUInt]: PT read getMutable;
     property Mutable[i : SizeUInt]: PT read getMutable;
@@ -80,7 +81,6 @@ implementation
 constructor TVector.TVectorEnumerator.Create(AVector: TVector);
 constructor TVector.TVectorEnumerator.Create(AVector: TVector);
 begin
 begin
   FVector := AVector;
   FVector := AVector;
-  FPosition := -1;
 end;
 end;
 
 
 function TVector.TVectorEnumerator.GetCurrent: T;
 function TVector.TVectorEnumerator.GetCurrent: T;
@@ -90,9 +90,14 @@ end;
 
 
 function TVector.TVectorEnumerator.MoveNext: Boolean;
 function TVector.TVectorEnumerator.MoveNext: Boolean;
 begin
 begin
-  Result := FPosition < FVector.Size - 1;
-  if Result then
-    inc(FPosition);
+  if not FFirstDone then begin
+    Result := FVector.Size > 0;
+    FFirstDone := True;
+  end else begin
+    Result := FPosition < FVector.Size - 1;
+    if Result then
+      inc(FPosition);
+  end;
 end;
 end;
 
 
 { TVector }
 { TVector }