瀏覽代碼

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 年之前
父節點
當前提交
c21b34daf1
共有 1 個文件被更改,包括 12 次插入7 次删除
  1. 12 7
      packages/fcl-stl/src/gvector.pp

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

@@ -45,10 +45,11 @@ type
     TVectorEnumerator = class
     private
       FVector: TVector;
-      FPosition: Integer;
+      FPosition: SizeUInt;
+      FFirstDone: Boolean;
+      function GetCurrent: T; inline;
     public
       constructor Create(AVector: TVector);
-      function GetCurrent: T; inline;
       function MoveNext: Boolean; inline;
       property Current: T read GetCurrent;
     end;
@@ -67,7 +68,7 @@ type
     procedure Reserve(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 Mutable[i : SizeUInt]: PT read getMutable;
@@ -80,7 +81,6 @@ implementation
 constructor TVector.TVectorEnumerator.Create(AVector: TVector);
 begin
   FVector := AVector;
-  FPosition := -1;
 end;
 
 function TVector.TVectorEnumerator.GetCurrent: T;
@@ -90,9 +90,14 @@ end;
 
 function TVector.TVectorEnumerator.MoveNext: Boolean;
 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;
 
 { TVector }