Revision | 267 (tree) |
---|---|
Zeit | 2016-05-30 02:49:51 |
Autor | twm |
pass the filename + '.LineIndex' to the TLineIndexes file so the index can be reused (requires writing permission in that directory for now)
@@ -4,7 +4,6 @@ | ||
4 | 4 | Forms, |
5 | 5 | w_LargeTextViewer in 'w_LargeTextViewer.pas' {f_LargeTextViewer}, |
6 | 6 | u_TextFileIndexer in 'u_TextFileIndexer.pas', |
7 | - u_Int64List in 'u_Int64List.pas', | |
8 | 7 | w_GotoLine in 'w_GotoLine.pas' {f_GotoLine}, |
9 | 8 | w_Search in 'w_Search.pas' {f_Search}, |
10 | 9 | JclUnicode in '..\libs\jcl\source\common\JclUnicode.pas', |
@@ -404,7 +404,6 @@ | ||
404 | 404 | <MainSource>MainSource</MainSource> |
405 | 405 | </DelphiCompile> |
406 | 406 | <DCCReference Include="..\libs\jcl\source\common\JclUnicode.pas" /> |
407 | - <DCCReference Include="u_Int64List.pas" /> | |
408 | 407 | <DCCReference Include="u_Int64ListFile.pas" /> |
409 | 408 | <DCCReference Include="u_LargeTextAccess.pas" /> |
410 | 409 | <DCCReference Include="u_TextFileIndexer.pas" /> |
@@ -5,7 +5,6 @@ | ||
5 | 5 | uses |
6 | 6 | SysUtils, |
7 | 7 | Classes, |
8 | - u_Int64List, | |
9 | 8 | u_Int64ListFile, |
10 | 9 | u_dzCriticalSection, |
11 | 10 | u_LargeTextAccess; |
@@ -14,8 +13,11 @@ | ||
14 | 13 | TTextFileIndexer = class |
15 | 14 | private |
16 | 15 | type |
17 | - TLineIndexes = TInt64ListFile; | |
18 | - private | |
16 | + TLineIndexes = class(TInt64ListFile) | |
17 | + private | |
18 | + procedure InitCount; | |
19 | + end; | |
20 | + private | |
19 | 21 | FCritSect: TdzCriticalSection; |
20 | 22 | FLineIndexes: TLineIndexes; |
21 | 23 | FIsDone: boolean; |
@@ -44,9 +46,9 @@ | ||
44 | 46 | constructor TTextFileIndexer.Create(const _Filename: string); |
45 | 47 | begin |
46 | 48 | inherited Create; |
47 | - FLineIndexes := TLineIndexes.Create; | |
48 | -// FLineIndexes.Capacity := MaxListSize; // OneGibiByte div SizeOf(Int64); | |
49 | 49 | FFilename := _Filename; |
50 | + FLineIndexes := TLineIndexes.Create(FFilename + '.LineIndex'); | |
51 | + FLineIndexes.InitCount; | |
50 | 52 | FCritSect := TdzCriticalSection.Create; |
51 | 53 | end; |
52 | 54 |
@@ -74,6 +76,10 @@ | ||
74 | 76 | lta: TLargeTextAccess; |
75 | 77 | begin |
76 | 78 | FAbortRequested := False; |
79 | + if FLineIndexes.Count > 0 then begin | |
80 | + FIsDone := True; | |
81 | + Exit; | |
82 | + end; | |
77 | 83 | FIsDone := False; |
78 | 84 | lta := TLargeTextAccess.Create(FFilename, ofForward); |
79 | 85 | try |
@@ -90,7 +96,7 @@ | ||
90 | 96 | finally |
91 | 97 | FreeAndNil(lta); |
92 | 98 | end; |
93 | - FIsDone := true; | |
99 | + FIsDone := True; | |
94 | 100 | end; |
95 | 101 | |
96 | 102 | function TTextFileIndexer.GetLineIndex(_Idx: integer): Int64; |
@@ -115,7 +121,25 @@ | ||
115 | 121 | |
116 | 122 | procedure TTextFileIndexer.Abort; |
117 | 123 | begin |
118 | - FAbortRequested := true; | |
124 | + FAbortRequested := True; | |
119 | 125 | end; |
120 | 126 | |
127 | +{ TTextFileIndexer.TLineIndexes } | |
128 | + | |
129 | +procedure TTextFileIndexer.TLineIndexes.InitCount; | |
130 | +var | |
131 | + Size: Int64; | |
132 | + Idx: Int64; | |
133 | +begin | |
134 | + Size := FTempFile.Size; | |
135 | + if (FCount = 0) and (Size > 0) and (Size mod SizeOf(FBuffer) = 0) then begin | |
136 | + FCount := Size div SizeOf(FCount); | |
137 | + Idx := FCount - 1; | |
138 | + while Items[Idx] = 0 do begin | |
139 | + Dec(Idx); | |
140 | + end; | |
141 | + FCount := Idx + 1; | |
142 | + end; | |
143 | +end; | |
144 | + | |
121 | 145 | end. |