LoadCodeBuffer now uses cache for virtual files

git-svn-id: trunk@8718 -
This commit is contained in:
mattias 2006-02-07 10:37:19 +00:00
parent c89be56e6f
commit fb3672a053
2 changed files with 28 additions and 0 deletions

View File

@ -44,6 +44,8 @@ uses
type
TCodeCache = class;
{ TCodeBuffer }
TCodeBuffer = class(TSourceLog)
private
FFilename: string;
@ -85,6 +87,7 @@ type
procedure IncrementRefCount;
procedure ReleaseRefCount;
procedure MakeFileDateValid;
function SourceIsText: boolean;
public
property CodeCache: TCodeCache read FCodeCache write FCodeCache;
property Filename: string read FFilename write SetFilename;
@ -853,6 +856,20 @@ begin
FLoadDate:=FileAge(Filename);
end;
function TCodeBuffer.SourceIsText: boolean;
var
l: LongInt;
i: Integer;
s: String;
begin
l:=SourceLength;
if l>1024 then l:=1024;
s:=Source;
for i:=1 to l do
if s[i] in [#0..#8,#11..#12,#14..#31] then exit(false);
Result:=true;
end;
function TCodeBuffer.FileDateOnDisk: longint;
begin
Result:=FileAge(Filename);

View File

@ -133,6 +133,17 @@ var
ACaption, AText: string;
FileReadable: boolean;
begin
if [lbfUpdateFromDisk,lbfRevert]*Flags=[] then begin
// can use cache
ACodeBuffer:=CodeToolBoss.LoadFile(AFilename,false,false);
if ACodeBuffer<>nil then begin
// file is in cache
if (not (lbfCheckIfText in Flags)) or ACodeBuffer.SourceIsText then begin
Result:=mrOk;
exit;
end;
end;
end;
repeat
FileReadable:=true;
if (lbfCheckIfText in Flags)