• R/O
  • SSH
  • HTTPS

dzlargetextview: Commit


Commit MetaInfo

Revision264 (tree)
Zeit2016-05-30 01:07:43
Autortwm

Log Message

* better error message
* summary comment

Ändern Zusammenfassung

Diff

--- trunk/src/u_Int64List.pas (revision 263)
+++ trunk/src/u_Int64List.pas (revision 264)
@@ -8,6 +8,13 @@
88 u_dzTranslator;
99
1010 type
11+ ///<summary>
12+ /// A List for storing Int64 values
13+ /// Note: If you use Add to add a huge amount of items to the list, you will
14+ /// likely get an EOutOfMemory exception before actually running out of memory
15+ /// because of memory framentation. If you know how many items you want to
16+ /// store, set Capacity to that number. Capacity can be set to a maximum of
17+ /// Classes.MaxListSize which means the list takes up around 1 GB of memory. </summary>
1118 TInt64List = class
1219 private
1320 FData: array of Int64;
@@ -16,7 +23,7 @@
1623 procedure Grow;
1724 procedure SetCapacity(_NewCapacity: integer);
1825 function GetItems(_Idx: integer): Int64;
19- procedure SetItems(_Idx: integer; const Value: Int64);
26+ procedure SetItems(_Idx: integer; const _Value: Int64);
2027 public
2128 function Add(_Value: Int64): integer;
2229 property Items[_Idx: integer]: Int64 read GetItems write SetItems;
@@ -26,9 +33,6 @@
2633
2734 implementation
2835
29-uses
30- RTLConsts;
31-
3236 { TInt64List }
3337
3438 function TInt64List.Add(_Value: Int64): integer;
@@ -55,9 +59,14 @@
5559
5660 procedure TInt64List.SetCapacity(_NewCapacity: integer);
5761 begin
58- if (_NewCapacity < FCount) or (_NewCapacity > MaxListSize) then
59- raise Exception.CreateFmt(_('List capacity out of bounds (%d)'), [_NewCapacity]);
6062 if _NewCapacity <> FCapacity then begin
63+ if (_NewCapacity < FCount) then
64+ raise Exception.CreateFmt(_('Cannot set list capacity (%d) to less than current item count (%d).'),
65+ [_NewCapacity, FCount]);
66+ if (_NewCapacity > MaxListSize) then
67+ raise Exception.CreateFmt(_('Cannot set list capacity (%d) higher than MaxListSize (%d).'),
68+ [_NewCapacity, MaxListSize]);
69+
6170 SetLength(FData, _NewCapacity);
6271 FCapacity := _NewCapacity;
6372 end;
@@ -66,13 +75,15 @@
6675 function TInt64List.GetItems(_Idx: integer): Int64;
6776 begin
6877 if (_Idx < 0) or (_Idx >= FCount) then
69- raise Exception.CreateFmt(_('List index out of bounds (%d)'), [_Idx]);
78+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
7079 Result := FData[_Idx];
7180 end;
7281
73-procedure TInt64List.SetItems(_Idx: integer; const Value: Int64);
82+procedure TInt64List.SetItems(_Idx: integer; const _Value: Int64);
7483 begin
75-
84+ if (_Idx < 0) or (_Idx >= FCount) then
85+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
86+ FData[_Idx] := _Value;
7687 end;
7788
7889 end.
--- trunk/src/u_Int64ListFile.pas (revision 263)
+++ trunk/src/u_Int64ListFile.pas (revision 264)
@@ -19,7 +19,7 @@
1919 FCount: Int64;
2020 FTempFile: TdzFile;
2121 function GetItems(_Idx: Int64): Int64;
22- procedure SetItems(_Idx: Int64; const Value: Int64);
22+ procedure SetItems(_Idx: Int64; const _Value: Int64);
2323 procedure AssureBufferFor(_Idx: integer);
2424 public
2525 constructor Create(_fn: string = '');
@@ -83,14 +83,17 @@
8383 function TInt64ListFile.GetItems(_Idx: Int64): Int64;
8484 begin
8585 if (_Idx < 0) or (_Idx >= FCount) then
86- raise Exception.CreateFmt(_('List index out of bounds (%d)'), [_Idx]);
86+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
8787 AssureBufferFor(_Idx);
8888 Result := FBuffer[_Idx - FOffset];
8989 end;
9090
91-procedure TInt64ListFile.SetItems(_Idx: Int64; const Value: Int64);
91+procedure TInt64ListFile.SetItems(_Idx: Int64; const _Value: Int64);
9292 begin
93-
93+ if (_Idx < 0) or (_Idx >= FCount) then
94+ raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]);
95+ AssureBufferFor(_Idx);
96+ FBuffer[_Idx - FOffset] := _Value;
9497 end;
9598
9699 end.
Show on old repository browser