summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-08-09 21:00:50 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-08-09 21:03:55 +0200
commit9d0ec2eb7fbc570d44901aa24745b420132b01da (patch)
tree7bed72b3ce05dffde8476a9b3ffbc907b1211424 /examples
parent155adcb223576a1548d22d7be1f5b1e29581254d (diff)
downloadfpGUI-9d0ec2eb7fbc570d44901aa24745b420132b01da.tar.xz
ide: huge speed improvement in syntax highlighting
Getting font resources are very costly. So now we cache the font used for reserved keyword highlighting and simple reuse it, instead of creating and freeing it for each line (like we did up 'till now). This caused a MASSIVE speed increase! :-D
Diffstat (limited to 'examples')
-rw-r--r--examples/apps/ide/src/frm_main.pas10
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas
index ccfcebba..2e14e333 100644
--- a/examples/apps/ide/src/frm_main.pas
+++ b/examples/apps/ide/src/frm_main.pas
@@ -57,6 +57,7 @@ type
miRecentProjects: TfpgMenuItem;
FRecentFiles: TfpgMRU;
FRegex: TRegExpr;
+ FKeywordFont: TfpgFont;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure btnQuitClicked(Sender: TObject);
@@ -633,7 +634,7 @@ procedure TMainForm.TextEditDrawLine(Sender: TObject; ALineText: TfpgString;
ALineIndex: Integer; ACanvas: TfpgCanvas; ATextRect: TfpgRect;
var AllowSelfDraw: Boolean);
var
- oldfont, newfont: TfpgFont;
+ oldfont: TfpgFont;
s: TfpgString; // copy of ALineText we work with
i, j, c: integer; // i = position of reserved word; c = last character pos
iLength: integer; // length of reserved word
@@ -657,8 +658,9 @@ begin
lOffset := 0;
{ syntax highlighting for: keywords }
- newfont := fpgGetFont(edt.FontDesc + ':bold');
- ACanvas.Font := newfont;
+ if not Assigned(FKeywordFont) then
+ FKeywordFont := fpgGetFont(edt.FontDesc + ':bold');
+ ACanvas.Font := FKeywordFont;
FRegex.Expression := cKeywords;
FRegex.ModifierI := True;
if FRegex.Exec(ALineText) then
@@ -710,7 +712,6 @@ begin
end;
ACanvas.Font := oldfont;
- newfont.Free;
// writeln('------');
end;
@@ -760,6 +761,7 @@ end;
destructor TMainForm.Destroy;
begin
FRegex.Free;
+ FKeywordFont.Free;
inherited Destroy;
end;