From c40bc842d55450a3393ec0de41de481b732dc9ad Mon Sep 17 00:00:00 2001 From: lazarus Date: Mon, 11 Mar 2002 18:12:11 +0000 Subject: [PATCH] MG: acclerated parser read-undo-read combinations git-svn-id: trunk@1501 - --- components/codetools/customcodetool.pas | 20 ++++++++--- components/codetools/pascalparsertool.pas | 3 +- lcl/include/graphic.inc | 43 ++++++++++------------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/components/codetools/customcodetool.pas b/components/codetools/customcodetool.pas index 2e12715c55..97dcc2b94f 100644 --- a/components/codetools/customcodetool.pas +++ b/components/codetools/customcodetool.pas @@ -68,6 +68,7 @@ type SrcLen: integer; CurNode: TCodeTreeNode; LastAtoms: TAtomRing; + NextPos: TAtomPosition; CheckFilesOnDisk: boolean; IndentSize: integer; @@ -199,6 +200,7 @@ begin CurPos.StartPos:=1; CurPos.EndPos:=-1; LastAtoms.Clear; + NextPos.StartPos:=-1; end; procedure TCustomCodeTool.RaiseException(const AMessage: string); @@ -539,11 +541,16 @@ procedure TCustomCodeTool.ReadNextAtom; var c1, c2: char; CommentLvl: integer; begin - // Skip all spaces and comments - CommentLvl:=0; if (CurPos.StartPos=1) then LastAtoms.Add(CurPos); + if NextPos.StartPos>=1 then begin + CurPos:=NextPos; + NextPos.StartPos:=-1; + exit; + end; CurPos.StartPos:=CurPos.EndPos; + // Skip all spaces and comments + CommentLvl:=0; //if CurPos.StartPos<1 then CurPos.StartPos:=SrcLen+1; while CurPos.StartPos<=SrcLen do begin if IsCommentStartChar[Src[CurPos.StartPos]] then begin @@ -747,6 +754,7 @@ begin UndoReadNextAtom; exit; end; + NextPos:=CurPos; // Skip all spaces and comments CommentLvl:=0; dec(CurPos.StartPos); @@ -1009,6 +1017,7 @@ end; procedure TCustomCodeTool.UndoReadNextAtom; begin if LastAtoms.Count>0 then begin + NextPos:=CurPos; CurPos:=LastAtoms.GetValueAt(0); LastAtoms.UndoLastAdd; end else @@ -1147,15 +1156,14 @@ begin CurPos.StartPos:=1; CurPos.EndPos:=1; LastAtoms.Clear; + NextPos.StartPos:=-1; CurNode:=nil; if DeleteNodes then DoDeleteNodes; end; procedure TCustomCodeTool.MoveCursorToNodeStart(ANode: TCodeTreeNode); begin - CurPos.StartPos:=ANode.StartPos; - CurPos.EndPos:=ANode.StartPos; - LastAtoms.Clear; + MoveCursorToCleanPos(ANode.StartPos); CurNode:=ANode; end; @@ -1164,6 +1172,7 @@ begin CurPos.StartPos:=ACleanPos; CurPos.EndPos:=ACleanPos; LastAtoms.Clear; + NextPos.StartPos:=-1; CurNode:=nil; end; @@ -1368,6 +1377,7 @@ begin // search first atom in line CurPos.StartPos:=ALineStart; CurPos.EndPos:=ALineStart; + NextPos.StartPos:=-1; ReadNextAtom; AFirstAtomStart:=CurPos.StartPos; // search last atom in line diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 0948f5b30c..b91249df2f 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -2960,8 +2960,7 @@ begin if (GrandPaNode=nil) or (GrandPaNode.Desc<>ctnClass) then exit; GrandPaNode:=GrandPaNode.Parent; if GrandPaNode.Desc<>ctnTypeDefinition then exit; - CurPos.StartPos:=GrandPaNode.StartPos; - CurPos.EndPos:=CurPos.StartPos; + MoveCursorToCleanPos(GrandPaNode.StartPos); ReadNextAtom; if not AtomIsWord then exit; TheClassName:=GetAtom; diff --git a/lcl/include/graphic.inc b/lcl/include/graphic.inc index 095f98a874..c1972dc28e 100644 --- a/lcl/include/graphic.inc +++ b/lcl/include/graphic.inc @@ -34,31 +34,27 @@ end; function TGraphic.Equals(Graphic: TGraphic): Boolean; var SelfImage, GraphicsImage: TMemoryStream; + IsEmpty: boolean; begin - Result := (Graphic <> nil); + Result := (Graphic <> nil) and (ClassType = Graphic.ClassType); if not Result then exit; - Result:=(ClassType = Graphic.ClassType); - if not Result then exit; - if Empty or Graphic.Empty then - begin - Result := Empty and Graphic.Empty; - Exit; - end; - if Result then begin - SelfImage := TMemoryStream.Create; + IsEmpty:=Empty; + Result:=(IsEmpty=Graphic.Empty); + if (not Result) or IsEmpty or (Self=Graphic) then exit; + // ToDo: check for same resource + SelfImage := TMemoryStream.Create; + try + WriteData(SelfImage); + GraphicsImage := TMemoryStream.Create; try - WriteData(SelfImage); - GraphicsImage := TMemoryStream.Create; - try - Graphic.WriteData(GraphicsImage); - Result := (SelfImage.Size = GraphicsImage.Size) and - CompareMem(SelfImage.Memory, GraphicsImage.Memory, SelfImage.Size); - finally - GraphicsImage.Free; - end; + Graphic.WriteData(GraphicsImage); + Result := (SelfImage.Size = GraphicsImage.Size) and + CompareMem(SelfImage.Memory, GraphicsImage.Memory, SelfImage.Size); finally - SelfImage.Free; + GraphicsImage.Free; end; + finally + SelfImage.Free; end; end; @@ -104,17 +100,16 @@ end; procedure TGraphic.SetModified(Value: Boolean); begin if Value then - FModified := true // Changed(Self); + Changed(Self); else FModified := False; end; procedure TGraphic.SetTransparent(Value: Boolean); begin - if Value <> FTransparent then - begin + if Value <> FTransparent then begin FTransparent := Value; - //Changed(Self); + Changed(Self); end; end;