mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:19:22 +02:00
TurboPowerIPro: Use IntegerList in unit IpStrms for FLineIndex list.
git-svn-id: trunk@56391 -
This commit is contained in:
parent
86aadcad56
commit
631f189a08
@ -41,14 +41,12 @@ unit IpStrms;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils,
|
SysUtils, Classes,
|
||||||
Classes,
|
|
||||||
{$IFDEF IP_LAZARUS}
|
{$IFDEF IP_LAZARUS}
|
||||||
FPCAdds,
|
// LCL
|
||||||
LCLType,
|
LCLType,
|
||||||
GraphType,
|
// LazUtils
|
||||||
LCLIntf,
|
FPCAdds, LazFileUtils, IntegerList,
|
||||||
LazFileUtils,
|
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Windows, // put Windows behind Classes because of THandle
|
Windows, // put Windows behind Classes because of THandle
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -190,7 +188,7 @@ type
|
|||||||
FLineCount : Longint;
|
FLineCount : Longint;
|
||||||
FLineCurrent : Longint;
|
FLineCurrent : Longint;
|
||||||
FLineCurOfs : Longint;
|
FLineCurOfs : Longint;
|
||||||
FLineIndex : TList;
|
FLineIndex : TIntegerList;
|
||||||
FLineInxStep : Longint;
|
FLineInxStep : Longint;
|
||||||
FLineInxTop : Integer;
|
FLineInxTop : Integer;
|
||||||
|
|
||||||
@ -1061,7 +1059,7 @@ procedure TIpAnsiTextStream.atsResetLineIndex;
|
|||||||
begin
|
begin
|
||||||
{make sure we have a line index}
|
{make sure we have a line index}
|
||||||
if (FLineIndex = nil) then begin
|
if (FLineIndex = nil) then begin
|
||||||
FLineIndex := TList.Create; {create the index: even elements are}
|
FLineIndex := TIntegerList.Create; {create the index: even elements are}
|
||||||
FLineIndex.Count := LineIndexCount * 2; {linenums, odd are offsets}
|
FLineIndex.Count := LineIndexCount * 2; {linenums, odd are offsets}
|
||||||
|
|
||||||
{if we didn't have a line index, set up some reasonable defaults}
|
{if we didn't have a line index, set up some reasonable defaults}
|
||||||
@ -1069,8 +1067,8 @@ begin
|
|||||||
FLineEndCh := #10; {not used straight away}
|
FLineEndCh := #10; {not used straight away}
|
||||||
FLineLen := 80; {not used straight away}
|
FLineLen := 80; {not used straight away}
|
||||||
end;
|
end;
|
||||||
FLineIndex[0] := pointer(0); {the first line is line 0 and...}
|
FLineIndex[0] := 0; {the first line is line 0 and...}
|
||||||
FLineIndex[1] := pointer(0); {...it starts at position 0}
|
FLineIndex[1] := 0; {...it starts at position 0}
|
||||||
FLineInxTop := 0; {the top valid index}
|
FLineInxTop := 0; {the top valid index}
|
||||||
FLineInxStep := 1; {step count before add a line to index}
|
FLineInxStep := 1; {step count before add a line to index}
|
||||||
FLineCount := -1; {number of lines (-1 = don't know)}
|
FLineCount := -1; {number of lines (-1 = don't know)}
|
||||||
@ -1305,10 +1303,10 @@ begin
|
|||||||
{if the offset requested is greater than the top item in the
|
{if the offset requested is greater than the top item in the
|
||||||
line index, we shall have to build up the index until we get to the
|
line index, we shall have to build up the index until we get to the
|
||||||
line we require, or just beyond}
|
line we require, or just beyond}
|
||||||
if (aOffset > {%H-}Longint(FLineIndex[FLineInxTop+1])) then begin
|
if aOffset > FLineIndex[FLineInxTop+1] then begin
|
||||||
{position at the last known line offset}
|
{position at the last known line offset}
|
||||||
CurLine := {%H-}Longint(FLineIndex[FLineInxTop]);
|
CurLine := FLineIndex[FLineInxTop];
|
||||||
CurOfs := {%H-}Longint(FLineIndex[FLineInxTop+1]);
|
CurOfs := FLineIndex[FLineInxTop+1];
|
||||||
Seek(CurOfs, soFromBeginning);
|
Seek(CurOfs, soFromBeginning);
|
||||||
Done := false;
|
Done := false;
|
||||||
{continue reading lines in chunks of FLineInxStep and add an index
|
{continue reading lines in chunks of FLineInxStep and add an index
|
||||||
@ -1338,8 +1336,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
FLineInxStep := FLineInxStep * 2;
|
FLineInxStep := FLineInxStep * 2;
|
||||||
end;
|
end;
|
||||||
FLineIndex[FLineInxTop] := {%H-}pointer(CurLine);
|
FLineIndex[FLineInxTop] := CurLine;
|
||||||
FLineIndex[FLineInxTop+1] := {%H-}pointer(CurOfs);
|
FLineIndex[FLineInxTop+1] := CurOfs;
|
||||||
if (aOffset <= CurOfs) then
|
if (aOffset <= CurOfs) then
|
||||||
Done := true;
|
Done := true;
|
||||||
end;
|
end;
|
||||||
@ -1353,13 +1351,13 @@ begin
|
|||||||
M := (L + R) div 2;
|
M := (L + R) div 2;
|
||||||
if not Odd(M) then
|
if not Odd(M) then
|
||||||
inc(M);
|
inc(M);
|
||||||
if (aOffset < {%H-}Longint(FLineIndex[M])) then
|
if aOffset < FLineIndex[M] then
|
||||||
R := M - 2
|
R := M - 2
|
||||||
else if (aOffset > {%H-}Longint(FLineIndex[M])) then
|
else if aOffset > FLineIndex[M] then
|
||||||
L := M + 2
|
L := M + 2
|
||||||
else begin
|
else begin
|
||||||
FLineCurrent := {%H-}Longint(FLineIndex[M-1]);
|
FLineCurrent := FLineIndex[M-1];
|
||||||
FLineCurOfs := {%H-}Longint(FLineIndex[M]);
|
FLineCurOfs := FLineIndex[M];
|
||||||
Seek(FLineCurOfs, soFromBeginning);
|
Seek(FLineCurOfs, soFromBeginning);
|
||||||
Result := FLineCurrent;
|
Result := FLineCurrent;
|
||||||
Exit;
|
Exit;
|
||||||
@ -1368,8 +1366,8 @@ begin
|
|||||||
{the item at L-2 will have the nearest smaller offset than the
|
{the item at L-2 will have the nearest smaller offset than the
|
||||||
one we want, hence the nearest smaller line is at L-3; start here
|
one we want, hence the nearest smaller line is at L-3; start here
|
||||||
and read through the stream forwards}
|
and read through the stream forwards}
|
||||||
CurLine := {%H-}Longint(FLineIndex[L-3]);
|
CurLine := FLineIndex[L-3];
|
||||||
Seek({%H-}Longint(FLineIndex[L-2]), soFromBeginning);
|
Seek(FLineIndex[L-2], soFromBeginning);
|
||||||
while true do begin
|
while true do begin
|
||||||
atsGetLine(CurPos, EndPos, Len);
|
atsGetLine(CurPos, EndPos, Len);
|
||||||
inc(CurLine);
|
inc(CurLine);
|
||||||
@ -1436,10 +1434,10 @@ begin
|
|||||||
{if the line number requested is greater than the top item in the
|
{if the line number requested is greater than the top item in the
|
||||||
line index, we shall have to build up the index until we get to the
|
line index, we shall have to build up the index until we get to the
|
||||||
line we require, or just beyond}
|
line we require, or just beyond}
|
||||||
if (aLineNum > {%H-}Longint(FLineIndex[FLineInxTop])) then begin
|
if aLineNum > FLineIndex[FLineInxTop] then begin
|
||||||
{position at the last known line offset}
|
{position at the last known line offset}
|
||||||
CurLine := {%H-}Longint(FLineIndex[FLineInxTop]);
|
CurLine := FLineIndex[FLineInxTop];
|
||||||
CurOfs := {%H-}Longint(FLineIndex[FLineInxTop+1]);
|
CurOfs := FLineIndex[FLineInxTop+1];
|
||||||
Seek(CurOfs, soFromBeginning);
|
Seek(CurOfs, soFromBeginning);
|
||||||
Done := false;
|
Done := false;
|
||||||
{continue reading lines in chunks of FLineInxStep and add an index
|
{continue reading lines in chunks of FLineInxStep and add an index
|
||||||
@ -1469,8 +1467,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
FLineInxStep := FLineInxStep * 2;
|
FLineInxStep := FLineInxStep * 2;
|
||||||
end;
|
end;
|
||||||
FLineIndex[FLineInxTop] := {%H-}pointer(CurLine);
|
FLineIndex[FLineInxTop] := CurLine;
|
||||||
FLineIndex[FLineInxTop+1] := {%H-}pointer(CurOfs);
|
FLineIndex[FLineInxTop+1] := CurOfs;
|
||||||
if (aLineNum <= CurLine) then
|
if (aLineNum <= CurLine) then
|
||||||
Done := true;
|
Done := true;
|
||||||
end;
|
end;
|
||||||
@ -1484,13 +1482,13 @@ begin
|
|||||||
M := (L + R) div 2;
|
M := (L + R) div 2;
|
||||||
if Odd(M) then
|
if Odd(M) then
|
||||||
dec(M);
|
dec(M);
|
||||||
if (aLineNum < {%H-}Longint(FLineIndex[M])) then
|
if aLineNum < FLineIndex[M] then
|
||||||
R := M - 2
|
R := M - 2
|
||||||
else if (aLineNum > {%H-}Longint(FLineIndex[M])) then
|
else if aLineNum > FLineIndex[M] then
|
||||||
L := M + 2
|
L := M + 2
|
||||||
else begin
|
else begin
|
||||||
FLineCurrent := {%H-}Longint(FLineIndex[M]);
|
FLineCurrent := FLineIndex[M];
|
||||||
FLineCurOfs := {%H-}Longint(FLineIndex[M+1]);
|
FLineCurOfs := FLineIndex[M+1];
|
||||||
Seek(FLineCurOfs, soFromBeginning);
|
Seek(FLineCurOfs, soFromBeginning);
|
||||||
Result := FLineCurrent;
|
Result := FLineCurrent;
|
||||||
Exit;
|
Exit;
|
||||||
@ -1498,8 +1496,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
{the item at L-2 will have the nearest smaller line number than the
|
{the item at L-2 will have the nearest smaller line number than the
|
||||||
one we want; start here and read through the stream forwards}
|
one we want; start here and read through the stream forwards}
|
||||||
CurLine := Longint({%H-}PtrInt(FLineIndex[L-2]));
|
CurLine := FLineIndex[L-2];
|
||||||
Seek(Longint({%H-}PtrInt(FLineIndex[L-1])), soFromBeginning);
|
Seek(FLineIndex[L-1], soFromBeginning);
|
||||||
while true do begin
|
while true do begin
|
||||||
atsGetLine(CurPos, EndPos, Len);
|
atsGetLine(CurPos, EndPos, Len);
|
||||||
inc(CurLine);
|
inc(CurLine);
|
||||||
|
Loading…
Reference in New Issue
Block a user