* removed lots of unnecessary copies of strings for syntax highlighting

This commit is contained in:
pierre 2002-09-12 08:42:07 +00:00
parent e1556bbcba
commit bfb97f6a4d
2 changed files with 96 additions and 99 deletions

View File

@ -139,7 +139,7 @@ type
function IsReservedWord(const S: string): boolean; virtual; function IsReservedWord(const S: string): boolean; virtual;
function IsAsmReservedWord(const S: string): boolean; virtual; function IsAsmReservedWord(const S: string): boolean; virtual;
function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual; function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; virtual; function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
{ CodeTemplates } { CodeTemplates }
function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual; function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
function SelectCodeTemplate(var ShortCut: string): boolean; virtual; function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
@ -420,7 +420,7 @@ type
PScrollBar; AIndicator: PIndicator); PScrollBar; AIndicator: PIndicator);
function IsReservedWord(const S: string): boolean; virtual; function IsReservedWord(const S: string): boolean; virtual;
function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual; function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; virtual; function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
function GetPalette: PPalette; virtual; function GetPalette: PPalette; virtual;
end; end;
@ -430,7 +430,7 @@ type
PScrollBar; AIndicator: PIndicator); PScrollBar; AIndicator: PIndicator);
function IsReservedWord(const S: string): boolean; virtual; function IsReservedWord(const S: string): boolean; virtual;
function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual; function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; virtual; function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
end; end;
function SearchFreeWindowNo: integer; function SearchFreeWindowNo: integer;
@ -947,16 +947,17 @@ begin
DoneTokens; DoneTokens;
end; end;
function IsFPReservedWord(S: string): boolean; function IsFPReservedWord(const S: string): boolean;
var _Is: boolean; var _Is: boolean;
Idx,Item: sw_integer; Idx,Item: sw_integer;
UpS: string;
begin begin
Idx:=length(S); _Is:=false; Idx:=length(S); _Is:=false;
if (Low(ReservedWords)<=Idx) and (Idx<=High(ReservedWords)) and if (Low(ReservedWords)<=Idx) and (Idx<=High(ReservedWords)) and
(ReservedWords[Idx]<>nil) and (ReservedWords[Idx]^.Count<>0) then (ReservedWords[Idx]<>nil) and (ReservedWords[Idx]^.Count<>0) then
begin begin
S:=UpcaseStr(S); UpS:=UpcaseStr(S);
_Is:=ReservedWords[Idx]^.Search(@S,Item); _Is:=ReservedWords[Idx]^.Search(@UpS,Item);
end; end;
IsFPReservedWord:=_Is; IsFPReservedWord:=_Is;
end; end;
@ -1117,62 +1118,71 @@ begin
CompileStamp:=0; CompileStamp:=0;
end; end;
Const
FreePascalSpecSymbolCount : array [TSpecSymbolClass] of integer =
(
3,{ssCommentPrefix}
1,{ssCommentSingleLinePrefix}
2,{ssCommentSuffix}
1,{ssStringPrefix}
1,{ssStringSuffix}
1,{ssDirectivePrefix}
1,{ssDirectiveSuffix}
1,{ssAsmPrefix}
1 {ssAsmSuffix}
);
FreePascalEmptyString : string[1] = '';
FreePascalCommentPrefix1 : string[1] = '{';
FreePascalCommentPrefix2 : string[2] = '(*';
FreePascalCommentPrefix3 : string[2] = '//';
FreePascalCommentSingleLinePrefix : string[2] = '//';
FreePascalCommentSuffix1 : string[1] = '{';
FreePascalCommentSuffix2 : string[2] = '*)';
FreePascalStringPrefix : string[1] = '''';
FreePascalStringSuffix : string[1] = '''';
FreePascalDirectivePrefix : string[2] = '{$';
FreePascalDirectiveSuffix : string[1] = '}';
FreePascalAsmPrefix : string[3] = 'ASM';
FreePascalAsmSuffix : string[3] = 'END';
function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
var Count: integer;
begin begin
case SpecClass of GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
ssCommentPrefix : Count:=3;
ssCommentSingleLinePrefix : Count:=1;
ssCommentSuffix : Count:=2;
ssStringPrefix : Count:=1;
ssStringSuffix : Count:=1;
ssAsmPrefix : Count:=1;
ssAsmSuffix : Count:=1;
ssDirectivePrefix : Count:=1;
ssDirectiveSuffix : Count:=1;
else
Count:=0;
end;
GetSpecSymbolCount:=Count;
end; end;
function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
begin begin
GetSpecSymbol:=true; GetSpecSymbol:=@FreePascalEmptyString;
case SpecClass of case SpecClass of
ssCommentPrefix : ssCommentPrefix :
case Index of case Index of
0 : Symbol:='{'; 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
1 : Symbol:='(*'; 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
2 : Symbol:='//'; 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
end; end;
ssCommentSingleLinePrefix : ssCommentSingleLinePrefix :
case Index of case Index of
0 : Symbol:='//'; 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
end; end;
ssCommentSuffix : ssCommentSuffix :
case Index of case Index of
0 : Symbol:='}'; 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
1 : Symbol:='*)'; 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
end; end;
ssStringPrefix : ssStringPrefix :
Symbol:=''''; GetSpecSymbol:=@FreePascalStringPrefix;
ssStringSuffix : ssStringSuffix :
Symbol:=''''; GetSpecSymbol:=@FreePascalStringSuffix;
{ must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM } { must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
ssAsmPrefix : ssAsmPrefix :
Symbol:='ASM'; GetSpecSymbol:=@FreePascalAsmPrefix;
ssAsmSuffix : ssAsmSuffix :
Symbol:='END'; GetSpecSymbol:=@FreePascalAsmSuffix;
ssDirectivePrefix : ssDirectivePrefix :
Symbol:='{$'; GetSpecSymbol:=@FreePascalDirectivePrefix;
ssDirectiveSuffix : ssDirectiveSuffix :
Symbol:='}'; GetSpecSymbol:=@FreePascalDirectiveSuffix;
else
begin
Symbol:='';
GetSpecSymbol:=false;
end;
end; end;
end; end;
@ -4227,11 +4237,10 @@ begin
GetSpecSymbolCount:=0; GetSpecSymbolCount:=0;
end; end;
function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
begin begin
Abstract; Abstract;
GetSpecSymbol:=false; GetSpecSymbol:=nil;
Symbol:='';
end; end;
function TFPMemo.IsReservedWord(const S: string): boolean; function TFPMemo.IsReservedWord(const S: string): boolean;
@ -4246,60 +4255,42 @@ begin
end; end;
function TFPCodeMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; function TFPCodeMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
var Count: integer;
begin begin
case SpecClass of GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
ssCommentPrefix : Count:=3;
ssCommentSingleLinePrefix : Count:=1;
ssCommentSuffix : Count:=2;
ssStringPrefix : Count:=1;
ssStringSuffix : Count:=1;
ssAsmPrefix : Count:=1;
ssAsmSuffix : Count:=1;
ssDirectivePrefix : Count:=1;
ssDirectiveSuffix : Count:=1;
else
Count:=0;
end;
GetSpecSymbolCount:=Count;
end; end;
function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
begin begin
GetSpecSymbol:=true; GetSpecSymbol:=@FreePascalEmptyString;
case SpecClass of case SpecClass of
ssCommentPrefix : ssCommentPrefix :
case Index of case Index of
0 : Symbol:='{'; 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
1 : Symbol:='(*'; 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
2 : Symbol:='//'; 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
end; end;
ssCommentSingleLinePrefix : ssCommentSingleLinePrefix :
case Index of case Index of
0 : Symbol:='//'; 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
end; end;
ssCommentSuffix : ssCommentSuffix :
case Index of case Index of
0 : Symbol:='}'; 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
1 : Symbol:='*)'; 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
end; end;
ssStringPrefix : ssStringPrefix :
Symbol:=''''; GetSpecSymbol:=@FreePascalStringPrefix;
ssStringSuffix : ssStringSuffix :
Symbol:=''''; GetSpecSymbol:=@FreePascalStringSuffix;
{ must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
ssAsmPrefix : ssAsmPrefix :
Symbol:='ASM'; GetSpecSymbol:=@FreePascalAsmPrefix;
ssAsmSuffix : ssAsmSuffix :
Symbol:='END'; GetSpecSymbol:=@FreePascalAsmSuffix;
ssDirectivePrefix : ssDirectivePrefix :
Symbol:='{$'; GetSpecSymbol:=@FreePascalDirectivePrefix;
ssDirectiveSuffix : ssDirectiveSuffix :
Symbol:='}'; GetSpecSymbol:=@FreePascalDirectiveSuffix;
else
begin
GetSpecSymbol:=false;
Symbol:='';
end;
end; end;
end; end;
@ -4369,7 +4360,10 @@ end;
END. END.
{ {
$Log$ $Log$
Revision 1.31 2002-09-11 11:23:48 pierre Revision 1.32 2002-09-12 08:42:07 pierre
* removed lots of unnecessary copies of strings for syntax highlighting
Revision 1.31 2002/09/11 11:23:48 pierre
* more changes to speed syntax highlighting up * more changes to speed syntax highlighting up
Revision 1.30 2002/09/11 10:05:10 pierre Revision 1.30 2002/09/11 10:05:10 pierre

View File

@ -562,7 +562,7 @@ type
public public
{ Syntax highlight support } { Syntax highlight support }
{a}function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual; {a}function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
{a}function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean; virtual; {a}function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
{a}function IsReservedWord(const S: string): boolean; virtual; {a}function IsReservedWord(const S: string): boolean; virtual;
{a}function IsAsmReservedWord(const S: string): boolean; virtual; {a}function IsAsmReservedWord(const S: string): boolean; virtual;
public public
@ -2093,7 +2093,7 @@ var
type TPartialType = (pmNone,pmLeft,pmRight,pmAny); type TPartialType = (pmNone,pmLeft,pmRight,pmAny);
function MatchesAnySpecSymbol(SClass: TSpecSymbolClass; PartialMatch: TPartialType): boolean; function MatchesAnySpecSymbol(SClass: TSpecSymbolClass; PartialMatch: TPartialType): boolean;
var S: string; var S: pstring;
I: Sw_integer; I: Sw_integer;
Match,Found: boolean; Match,Found: boolean;
begin begin
@ -2102,23 +2102,23 @@ var
for I:=1 to Editor^.GetSpecSymbolCount(SClass) do for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
begin begin
SymbolIndex:=I; SymbolIndex:=I;
Editor^.GetSpecSymbol(SClass,I-1,S); S:=Editor^.GetSpecSymbol(SClass,I-1);
if (length(SymbolConcat)<length(S)) or if (length(SymbolConcat)<length(S^)) or
((PartialMatch=pmNone) and (length(S)<>length(SymbolConcat))) ((PartialMatch=pmNone) and (length(S^)<>length(SymbolConcat)))
then then
Match:=false Match:=false
else else
begin begin
case PartialMatch of case PartialMatch of
pmNone : Match:=SymbolConcat=S; pmNone : Match:=SymbolConcat=S^;
pmRight: pmRight:
Match:=copy(SymbolConcat,length(SymbolConcat)-length(S)+1,length(S))=S; Match:=copy(SymbolConcat,length(SymbolConcat)-length(S^)+1,length(S^))=S^;
else Match:=MatchSymbol(SymbolConcat,S); else Match:=MatchSymbol(SymbolConcat,S^);
end; end;
end; end;
if Match then if Match then
begin begin
MatchingSymbol:=S; Found:=true; Break; MatchingSymbol:=S^; Found:=true; Break;
end; end;
end; end;
MatchedSymbol:=MatchedSymbol or Found; MatchedSymbol:=MatchedSymbol or Found;
@ -2126,7 +2126,8 @@ var
end; end;
function MatchesAsmSpecSymbol(Const OrigWhat: string; SClass: TSpecSymbolClass): boolean; function MatchesAsmSpecSymbol(Const OrigWhat: string; SClass: TSpecSymbolClass): boolean;
var What, S: string; var What : String;
S: pstring;
I: Sw_integer; I: Sw_integer;
Match,Found: boolean; Match,Found: boolean;
begin begin
@ -2136,8 +2137,8 @@ var
for I:=1 to Editor^.GetSpecSymbolCount(SClass) do for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
begin begin
SymbolIndex:=I; SymbolIndex:=I;
Editor^.GetSpecSymbol(SClass,I-1,S); S:=Editor^.GetSpecSymbol(SClass,I-1);
if (length(S)<>length(What)) then if (length(S^)<>length(What)) then
Match:=false Match:=false
else else
begin begin
@ -2145,7 +2146,7 @@ var
S:=UpcaseStr(S); asm symbols need to be uppercased PM } S:=UpcaseStr(S); asm symbols need to be uppercased PM }
{case PartialMatch of {case PartialMatch of
pmNone : } pmNone : }
Match:=What=S; Match:=What=S^;
{ pmRight: { pmRight:
Match:=copy(What,length(What)-length(S)+1,length(S))=S; Match:=copy(What,length(What)-length(S)+1,length(S))=S;
else Match:=MatchSymbol(What,S); else Match:=MatchSymbol(What,S);
@ -2153,7 +2154,7 @@ var
end; end;
if Match then if Match then
begin begin
MatchingSymbol:=S; MatchingSymbol:=S^;
Found:=true; Found:=true;
Break; Break;
end; end;
@ -2312,7 +2313,7 @@ var
procedure ProcessChar(C: char); procedure ProcessChar(C: char);
var CC: TCharClass; var CC: TCharClass;
EX: Sw_integer; EX: Sw_integer;
EndComment: string; EndComment: pstring;
begin begin
CC:=GetCharClass(C); CC:=GetCharClass(C);
if ClassStart=X then if ClassStart=X then
@ -2376,8 +2377,8 @@ var
{ Remove (* from SymbolConcat to avoid problem with (*) PM } { Remove (* from SymbolConcat to avoid problem with (*) PM }
{ fixes part of bug 1617 } { fixes part of bug 1617 }
{ but removed proper directive prefix detection ... } { but removed proper directive prefix detection ... }
Editor^.GetSpecSymbol(ssCommentSuffix,SymbolIndex,EndComment); EndComment:=Editor^.GetSpecSymbol(ssCommentSuffix,SymbolIndex);
if MatchingSymbol[length(MatchingSymbol)]=EndComment[1] then if MatchingSymbol[length(MatchingSymbol)]=EndComment^[1] then
Delete(SymbolConcat,1,length(MatchingSymbol)); Delete(SymbolConcat,1,length(MatchingSymbol));
end end
else if InComment and IsCommentSuffix then else if InComment and IsCommentSuffix then
@ -3114,11 +3115,10 @@ begin
GetSpecSymbolCount:=0; GetSpecSymbolCount:=0;
end; end;
function TCustomCodeEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string):boolean; function TCustomCodeEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
begin begin
Abstract; Abstract;
Symbol:=''; GetSpecSymbol:=nil;
GetSpecSymbol:=false;
end; end;
function TCustomCodeEditor.IsReservedWord(const S: string): boolean; function TCustomCodeEditor.IsReservedWord(const S: string): boolean;
@ -7179,7 +7179,10 @@ end;
END. END.
{ {
$Log$ $Log$
Revision 1.35 2002-09-11 13:11:54 pierre Revision 1.36 2002-09-12 08:42:07 pierre
* removed lots of unnecessary copies of strings for syntax highlighting
Revision 1.35 2002/09/11 13:11:54 pierre
* speed up by using fixed char sets in GetCharClass * speed up by using fixed char sets in GetCharClass
Revision 1.34 2002/09/11 11:23:48 pierre Revision 1.34 2002/09/11 11:23:48 pierre