From 885dfcc9501392da7b8e170e545d4b2588efda5c Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 27 May 2010 21:03:57 +0000 Subject: [PATCH] ColorSchemFactory: improved loading speed git-svn-id: trunk@25712 - --- ide/editoroptions.pp | 43 ++++++++++++++++++++++++----- ide/frames/editor_color_options.pas | 1 + 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ide/editoroptions.pp b/ide/editoroptions.pp index fbb43c7509..b342fece31 100644 --- a/ide/editoroptions.pp +++ b/ide/editoroptions.pp @@ -210,6 +210,12 @@ type type (* *** ColorSchemes *** *) + { TQuickStringlist } + + TQuickStringlist=class(TStringlist) + Function DoCompareText(const s1,s2 : string) : PtrInt; override; + end; + TColorScheme = class; TColorSchemeLanguage = class; @@ -246,7 +252,7 @@ type TColorSchemeLanguage = class(TObject) private FDefaultAttribute: TColorSchemeAttribute; - FAttributes: TStringList; // TColorSchemeAttribute + FAttributes: TQuickStringlist; // TColorSchemeAttribute FHighlighter: TSynCustomHighlighter; FLanguage: TLazSyntaxHighlighter; FOwner: TColorScheme; @@ -312,7 +318,7 @@ type TColorSchemeFactory = class(TObject) private - FMappings: TStringList; // TColorScheme + FMappings: TQuickStringlist; // TColorScheme function GetColorSchemeGroup(Index: String): TColorScheme; function GetColorSchemeGroupAtPos(Index: Integer): TColorScheme; public @@ -4157,7 +4163,7 @@ constructor TColorSchemeLanguage.Create(const AGroup: TColorScheme; begin inherited Create; FIsSchemeDefault := IsSchemeDefault; - FAttributes := TStringList.Create; + FAttributes := TQuickStringlist.Create; FOwner := AGroup; FHighlighter := nil; FLanguage := ALang; @@ -4168,7 +4174,7 @@ begin FDefaultAttribute := TColorSchemeAttribute.Create(Self, dlgAddHiAttrDefault, 'ahaDefault'); FDefaultAttribute.Features := [hafBackColor, hafForeColor]; FDefaultAttribute.Group := agnDefault; - FAttributes.AddObject(FDefaultAttribute.StoredName, FDefaultAttribute); + FAttributes.AddObject(UpperCase(FDefaultAttribute.StoredName), FDefaultAttribute); FAttributes.Sorted := true; end; @@ -4230,14 +4236,14 @@ procedure TColorSchemeLanguage.Assign(Src: TColorSchemeLanguage); var i, j: Integer; Attr: TColorSchemeAttribute; - NewList: TStringList; + NewList: TQuickStringlist; begin // Do not clear old list => external references to Attributes may exist FLanguage := Src.FLanguage; FLanguageName := src.FLanguageName; //FDefaultAttribute.Assign(Src.FDefaultAttribute); FDefaultAttribute := nil; - NewList := TStringList.Create; + NewList := TQuickStringlist.Create; for i := 0 to Src.AttributeCount - 1 do begin j := FAttributes.IndexOf(UpperCase(Src.AttributeAtPos[i].Name)); if j >= 0 then begin @@ -4647,7 +4653,7 @@ end; constructor TColorSchemeFactory.Create; begin inherited Create; - FMappings := TStringList.Create; + FMappings := TQuickStringlist.Create; FMappings.Sorted := true; end; @@ -4754,6 +4760,29 @@ begin end; end; +{ TQuickStringlist } + +function TQuickStringlist.DoCompareText(const s1, s2: string): PtrInt; +var + i, l: Integer; +begin + Result := length(s1) - length(s2); + if Result <> 0 then + exit; + i := 1; + if Result < 0 then + l := length(s1) + else + l := length(s2); + while i < l do begin + Result := ord(s1[i]) - ord(s2[i]); + if Result <> 0 then + exit; + inc(i); + end; + Result := 0; +end; + initialization RegisterIDEOptionsGroup(GroupEditor, TEditorOptions); {$I lazarus_dci.lrs} diff --git a/ide/frames/editor_color_options.pas b/ide/frames/editor_color_options.pas index b092bbe35e..ad211be2cc 100644 --- a/ide/frames/editor_color_options.pas +++ b/ide/frames/editor_color_options.pas @@ -1066,6 +1066,7 @@ begin LanguageLabel.Caption := dlgLang; ColorSchemeLabel.Caption := dlgClrScheme; + ColorSchemeComboBox.Sorted := True; with ColorSchemeComboBox do begin ColorSchemeFactory.GetRegisteredSchemes(Items);