codetools: accelerated TSourceLog.BuildLineRanges

git-svn-id: trunk@25670 -
This commit is contained in:
mattias 2010-05-26 22:11:33 +00:00
parent aa707c4feb
commit 9590345c0c

View File

@ -84,7 +84,7 @@ type
destructor Destroy; override; destructor Destroy; override;
end; end;
TLineRange = record TLineRange = packed record
StartPos, EndPos: integer; StartPos, EndPos: integer;
end; end;
PLineRange = ^TLineRange; PLineRange = ^TLineRange;
@ -629,41 +629,45 @@ end;
procedure TSourceLog.BuildLineRanges; procedure TSourceLog.BuildLineRanges;
var var
p,line:integer; line:integer;
Cap: Integer; Cap: Integer;
SrcEnd: PChar;
SrcStart: PChar;
p: PChar;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF} {$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-} {$R-}
//DebugLn('[TSourceLog.BuildLineRanges] A Self=',DbgS(Self),',LineCount=',FLineCount,' Len=',SourceLength); //DebugLn(['[TSourceLog.BuildLineRanges] A Self=',DbgS(Self),',LineCount=',FLineCount,' Len=',SourceLength]);
if FLineCount>=0 then exit; if FLineCount>=0 then exit;
if FLineRanges<>nil then begin
FreeMem(FLineRanges);
FLineRanges:=nil;
end;
// build line range list // build line range list
FLineCount:=0; FLineCount:=0;
if FSource='' then exit; if FSource='' then begin
Cap:=100; ReAllocMem(FLineRanges,0);
GetMem(FLineRanges,Cap*SizeOf(TLineRange)); exit;
p:=1; end;
Cap:=length(FSource) div 20+100;
ReAllocMem(FLineRanges,Cap*SizeOf(TLineRange));
line:=0; line:=0;
FLineRanges[line].StartPos:=1; FLineRanges[line].StartPos:=1;
while (p<=fSrcLen) do begin SrcStart:=PChar(FSource);
if (not (FSource[p] in [#10,#13])) then begin SrcEnd:=SrcStart+FSrcLen;
p:=SrcStart;
while (p<SrcEnd) do begin
if (not (p^ in [#10,#13])) then begin
inc(p); inc(p);
end else begin end else begin
// new line // new line
FLineRanges[line].EndPos:=p; FLineRanges[line].EndPos:=p-SrcStart+1;
inc(line); inc(line);
if line>=Cap then begin if line>=Cap then begin
Cap:=Cap*2; Cap:=Cap*2;
ReAllocMem(FLineRanges,Cap*SizeOf(TLineRange)); ReAllocMem(FLineRanges,Cap*SizeOf(TLineRange));
end; end;
inc(p); if (p[1] in [#10,#13]) and (p^<>p[1]) then
if (p<=fSrcLen) and (FSource[p] in [#10,#13]) inc(p,2)
and (FSource[p]<>FSource[p-1]) then else
inc(p); inc(p);
FLineRanges[line].StartPos:=p; FLineRanges[line].StartPos:=p-SrcStart+1;
end; end;
end; end;
FLineRanges[line].EndPos:=fSrcLen+1; FLineRanges[line].EndPos:=fSrcLen+1;