Skip to content

Commit

Permalink
Merge latest changes from official SynEdit repository. Fixes slow hig…
Browse files Browse the repository at this point in the history
…hlighter when TableNames contains several 1000's of strings. Removes limitation to 1000 table names for highlighting. See

* http://www.heidisql.com/forum.php?t=16307
* SynEdit/SynEdit#28
  • Loading branch information
ansgarbecker committed Aug 15, 2016
1 parent 5534275 commit 7d7b78f
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 11 deletions.
3 changes: 3 additions & 0 deletions components/synedit/Source/SynAutoCorrectEditor.pas
Expand Up @@ -50,6 +50,9 @@ interface
QSynAutoCorrect,
QSynUnicode,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
Types,
{$ENDIF}
Windows, Messages, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,
Buttons, Registry,
SynAutoCorrect,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynCompletionProposal.pas
Expand Up @@ -68,6 +68,9 @@ interface
QSynEdit,
QSynUnicode,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
Types, UITypes,
{$ENDIF}
Windows,
Messages,
Graphics,
Expand Down
2 changes: 1 addition & 1 deletion components/synedit/Source/SynDBEdit.pas
Expand Up @@ -256,7 +256,7 @@ procedure TCustomDBSynEdit.CMExit(var Msg: TCMExit);

procedure TCustomDBSynEdit.CMGetDataLink(var Msg: TMessage);
begin
Msg.Result := Integer(FDataLink);
Msg.Result := LRESULT(FDataLink);
end;
{$ENDIF}

Expand Down
6 changes: 4 additions & 2 deletions components/synedit/Source/SynEdit.pas
Expand Up @@ -83,7 +83,7 @@ interface
Themes,
{$ENDIF}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
Types, UITypes,
{$ENDIF}
SynUnicode,
{$ENDIF}
Expand Down Expand Up @@ -1564,7 +1564,7 @@ procedure TCustomSynEdit.CreateParams(var Params: TCreateParams);
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
// avoid flicker while scrolling or resizing
if CheckWin32Version(5, 1) then
if not (csDesigning in ComponentState) and CheckWin32Version(5, 1) then
ExStyle := ExStyle or WS_EX_COMPOSITED;
end;

Expand Down Expand Up @@ -5129,7 +5129,9 @@ procedure TCustomSynEdit.WMCut(var Message: TMessage);
procedure TCustomSynEdit.WMDropFiles(var Msg: TMessage);
var
i, iNumberDropped: Integer;
{$IFNDEF UNICODE}
FileNameA: array[0..MAX_PATH - 1] of AnsiChar;
{$ENDIF}
FileNameW: array[0..MAX_PATH - 1] of WideChar;
Point: TPoint;
FilesList: TUnicodeStringList;
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditKeyCmdEditor.pas
Expand Up @@ -57,6 +57,9 @@ interface
QSynEditKeyCmds,
QSynEditMiscClasses,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
{$ENDIF}
Windows,
Messages,
Graphics,
Expand Down
6 changes: 6 additions & 0 deletions components/synedit/Source/SynEditKeyCmdsEditor.pas
Expand Up @@ -57,6 +57,12 @@ interface
QButtons,
QSynEditKeyCmds,
{$ELSE}
{$IFDEF SYN_COMPILER_15_UP}
Types,
{$ENDIF}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
{$ENDIF}
Windows,
Messages,
Graphics,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditOptionsDialog.pas
Expand Up @@ -63,6 +63,9 @@ interface
QSynEditMiscClasses,
QSynEditKeyCmds,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
Types,
{$ENDIF}
Windows,
Messages,
Graphics,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditPlugins.pas
Expand Up @@ -52,6 +52,9 @@ interface
QSynEditKeyCmds,
QSynUnicode,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
Types,
{$ENDIF}
Windows,
Menus,
SynEdit,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditPrint.pas
Expand Up @@ -107,6 +107,9 @@ interface
QSynEditHighlighter,
QSynUnicode,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
{$ENDIF}
Windows,
Graphics,
Printers,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditPrintHeaderFooter.pas
Expand Up @@ -111,6 +111,9 @@ interface
QSynUnicode,
QGraphics,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
{$ENDIF}
Windows,
SynEditPrintTypes,
SynEditPrintMargins,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditPrintMarginsDialog.pas
Expand Up @@ -63,6 +63,9 @@ interface
QSynEditPrintTypes,
QSynEditPrintMargins,
{$ELSE}
{$IFDEF SYN_COMPILER_17_UP}
UITypes,
{$ENDIF}
Windows,
Graphics,
Forms,
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynEditPrintPreview.pas
Expand Up @@ -65,6 +65,9 @@ interface
{$IFDEF SYN_COMPILER_7}
Themes,
{$ENDIF}
{$IFDEF SYN_COMPILER_17_UP}
Types,
{$ENDIF}
Windows,
Controls,
Messages,
Expand Down
3 changes: 1 addition & 2 deletions components/synedit/Source/SynHighlighterPython.pas
Expand Up @@ -224,14 +224,13 @@ function TSynPythonSyn.GetKeywordIdentifiers: TUnicodeStringList;
);

// List of non-keyword identifiers
NONKEYWORDCOUNT = 66;
NONKEYWORDCOUNT = 65;
NONKEYWORDS: array [1..NONKEYWORDCOUNT] of UnicodeString =
(
'__future__',
'__import__',
'abs',
'apply',
'as',
'buffer',
'callable',
'chr',
Expand Down
31 changes: 30 additions & 1 deletion components/synedit/Source/SynHighlighterSQL.pas
Expand Up @@ -55,6 +55,10 @@

interface

{$IFDEF SYN_COMPILER_12_UP}
{$DEFINE USE_TABLE_DICTIONARY}
{$ENDIF}

uses
{$IFDEF SYN_CLX}
Types,
Expand All @@ -71,6 +75,9 @@ interface
SynHighlighterHashEntries,
SynUnicode,
{$ENDIF}
{$IFDEF USE_TABLE_DICTIONARY}
Generics.Collections,
{$ENDIF}
SysUtils,
Classes;

Expand All @@ -93,6 +100,9 @@ TSynSQLSyn = class(TSynCustomHighlighter)
fKeywords: TSynHashEntryList;
fProcNames: TUnicodeStrings;
fTableNames: TUnicodeStrings;
{$IFDEF USE_TABLE_DICTIONARY}
fTableDict: TDictionary<string, Boolean>;
{$ENDIF}
fFunctionNames: TUniCodeStrings;
fDialect: TSQLDialect;
fCommentAttri: TSynHighlighterAttributes;
Expand Down Expand Up @@ -1238,7 +1248,12 @@ function TSynSQLSyn.IdentKind(MayBe: PWideChar): TtkTokenKind;
end;
Entry := Entry.Next;
end;
Result := tkIdentifier;
{$IFDEF USE_TABLE_DICTIONARY}
if fTableDict.ContainsKey(SynWideLowerCase(Copy(StrPas(fToIdent), 1, fStringLen))) then
Result := tkTableName
else
{$ENDIF}
Result := tkIdentifier;
end;

constructor TSynSQLSyn.Create(AOwner: TComponent);
Expand All @@ -1254,6 +1269,9 @@ constructor TSynSQLSyn.Create(AOwner: TComponent);

fTableNames := TUnicodeStringList.Create;
TUnicodeStringList(fTableNames).OnChange := TableNamesChanged;
{$IFDEF USE_TABLE_DICTIONARY}
fTableDict := TDictionary<string, Boolean>.Create;
{$ENDIF}

fFunctionNames := TunicodeStringList.Create;
TUnicodeStringList(fFunctionNames).OnChange := FunctionNamesChanged;
Expand Down Expand Up @@ -1317,6 +1335,9 @@ destructor TSynSQLSyn.Destroy;
fKeywords.Free;
fProcNames.Free;
fTableNames.Free;
{$IFDEF USE_TABLE_DICTIONARY}
fTableDict.Free;
{$ENDIF}
fFunctionNames.Free;
inherited Destroy;
end;
Expand Down Expand Up @@ -1895,7 +1916,12 @@ procedure TSynSQLSyn.PutTableNamesInKeywordList;
Entry := Entry.Next;
end;
if not Assigned(Entry) then
{$IFDEF USE_TABLE_DICTIONARY}
if not fTableDict.ContainsKey(SynWideLowerCase(fTableNames[i])) then
fTableDict.Add(SynWideLowerCase(fTableNames[i]), True);
{$ELSE}
DoAddKeyword(fTableNames[i], Ord(tkTableName));
{$ENDIF}
end;
end;

Expand Down Expand Up @@ -1946,6 +1972,9 @@ procedure TSynSQLSyn.InitializeKeywordLists;
{$ELSE}
fKeywords.Clear;
{$ENDIF}
{$IFDEF USE_TABLE_DICTIONARY}
fTableDict.Clear;
{$ENDIF}

for I := 0 to Ord(High(TtkTokenKind)) - 1 do
EnumerateKeywords(I, GetKeywords(I), IsIdentChar, DoAddKeyword);
Expand Down
2 changes: 2 additions & 0 deletions components/synedit/Source/SynRegExpr.pas
Expand Up @@ -1296,7 +1296,9 @@ class function TRegExpr.ParseModifiersStr (const AModifiers : RegExprString;
begin
Result := true;
IsOn := true;
{$IFNDEF SYN_COMPILER_24_UP}
Mask := 0; // prevent compiler warning
{$ENDIF}
for i := 1 to length (AModifiers) do
if AModifiers [i] = '-'
then IsOn := false
Expand Down
3 changes: 3 additions & 0 deletions components/synedit/Source/SynTextDrawer.pas
Expand Up @@ -68,6 +68,9 @@
interface

uses
{$IFDEF SYN_COMPILER_17_UP}
Types, UITypes,
{$ENDIF}
SynUnicode,
SysUtils,
Classes,
Expand Down
8 changes: 3 additions & 5 deletions source/main.pas
Expand Up @@ -8068,14 +8068,12 @@ procedure TMainForm.ObjectnamesChanged(Connection: TDBConnection; Database: Stri
for Obj in DBObjects do begin
case Obj.NodeType of
lntTable, lntView: begin
// Limit slow highlighter to 1000 table names. See http://www.heidisql.com/forum.php?t=16307
// Slow highlighter enhanced by uschuster. See http://www.heidisql.com/forum.php?t=16307
// ... and here: https://github.com/SynEdit/SynEdit/issues/28
if TableNames.Count < 1000 then
TableNames.Add(Obj.Name);
TableNames.Add(Obj.Name);
end;
lntProcedure, lntFunction: begin
if ProcNames.Count < 1000 then
ProcNames.Add(Obj.Name);
ProcNames.Add(Obj.Name);
end;
end;
end;
Expand Down

0 comments on commit 7d7b78f

Please sign in to comment.