mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 11:09:27 +02:00
* removed lots of unnecessary copies of strings for syntax highlighting
This commit is contained in:
parent
e1556bbcba
commit
bfb97f6a4d
150
ide/fpviews.pas
150
ide/fpviews.pas
@ -139,7 +139,7 @@ type
|
||||
function IsReservedWord(const S: string): boolean; virtual;
|
||||
function IsAsmReservedWord(const S: string): boolean; 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 }
|
||||
function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
|
||||
function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
|
||||
@ -420,7 +420,7 @@ type
|
||||
PScrollBar; AIndicator: PIndicator);
|
||||
function IsReservedWord(const S: string): boolean; 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;
|
||||
end;
|
||||
|
||||
@ -430,7 +430,7 @@ type
|
||||
PScrollBar; AIndicator: PIndicator);
|
||||
function IsReservedWord(const S: string): boolean; 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;
|
||||
|
||||
function SearchFreeWindowNo: integer;
|
||||
@ -947,16 +947,17 @@ begin
|
||||
DoneTokens;
|
||||
end;
|
||||
|
||||
function IsFPReservedWord(S: string): boolean;
|
||||
function IsFPReservedWord(const S: string): boolean;
|
||||
var _Is: boolean;
|
||||
Idx,Item: sw_integer;
|
||||
UpS: string;
|
||||
begin
|
||||
Idx:=length(S); _Is:=false;
|
||||
if (Low(ReservedWords)<=Idx) and (Idx<=High(ReservedWords)) and
|
||||
(ReservedWords[Idx]<>nil) and (ReservedWords[Idx]^.Count<>0) then
|
||||
begin
|
||||
S:=UpcaseStr(S);
|
||||
_Is:=ReservedWords[Idx]^.Search(@S,Item);
|
||||
UpS:=UpcaseStr(S);
|
||||
_Is:=ReservedWords[Idx]^.Search(@UpS,Item);
|
||||
end;
|
||||
IsFPReservedWord:=_Is;
|
||||
end;
|
||||
@ -1117,62 +1118,71 @@ begin
|
||||
CompileStamp:=0;
|
||||
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;
|
||||
var Count: integer;
|
||||
begin
|
||||
case SpecClass of
|
||||
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;
|
||||
GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
|
||||
end;
|
||||
|
||||
function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean;
|
||||
function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
|
||||
begin
|
||||
GetSpecSymbol:=true;
|
||||
GetSpecSymbol:=@FreePascalEmptyString;
|
||||
case SpecClass of
|
||||
ssCommentPrefix :
|
||||
case Index of
|
||||
0 : Symbol:='{';
|
||||
1 : Symbol:='(*';
|
||||
2 : Symbol:='//';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
|
||||
1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
|
||||
2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
|
||||
end;
|
||||
ssCommentSingleLinePrefix :
|
||||
case Index of
|
||||
0 : Symbol:='//';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
|
||||
end;
|
||||
ssCommentSuffix :
|
||||
case Index of
|
||||
0 : Symbol:='}';
|
||||
1 : Symbol:='*)';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
|
||||
1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
|
||||
end;
|
||||
ssStringPrefix :
|
||||
Symbol:='''';
|
||||
GetSpecSymbol:=@FreePascalStringPrefix;
|
||||
ssStringSuffix :
|
||||
Symbol:='''';
|
||||
GetSpecSymbol:=@FreePascalStringSuffix;
|
||||
{ must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
|
||||
ssAsmPrefix :
|
||||
Symbol:='ASM';
|
||||
GetSpecSymbol:=@FreePascalAsmPrefix;
|
||||
ssAsmSuffix :
|
||||
Symbol:='END';
|
||||
GetSpecSymbol:=@FreePascalAsmSuffix;
|
||||
ssDirectivePrefix :
|
||||
Symbol:='{$';
|
||||
GetSpecSymbol:=@FreePascalDirectivePrefix;
|
||||
ssDirectiveSuffix :
|
||||
Symbol:='}';
|
||||
else
|
||||
begin
|
||||
Symbol:='';
|
||||
GetSpecSymbol:=false;
|
||||
end;
|
||||
GetSpecSymbol:=@FreePascalDirectiveSuffix;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -4227,11 +4237,10 @@ begin
|
||||
GetSpecSymbolCount:=0;
|
||||
end;
|
||||
|
||||
function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean;
|
||||
function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
|
||||
begin
|
||||
Abstract;
|
||||
GetSpecSymbol:=false;
|
||||
Symbol:='';
|
||||
GetSpecSymbol:=nil;
|
||||
end;
|
||||
|
||||
function TFPMemo.IsReservedWord(const S: string): boolean;
|
||||
@ -4246,60 +4255,42 @@ begin
|
||||
end;
|
||||
|
||||
function TFPCodeMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
|
||||
var Count: integer;
|
||||
begin
|
||||
case SpecClass of
|
||||
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;
|
||||
GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
|
||||
end;
|
||||
|
||||
function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string): boolean;
|
||||
function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
|
||||
begin
|
||||
GetSpecSymbol:=true;
|
||||
GetSpecSymbol:=@FreePascalEmptyString;
|
||||
case SpecClass of
|
||||
ssCommentPrefix :
|
||||
case Index of
|
||||
0 : Symbol:='{';
|
||||
1 : Symbol:='(*';
|
||||
2 : Symbol:='//';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
|
||||
1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
|
||||
2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
|
||||
end;
|
||||
ssCommentSingleLinePrefix :
|
||||
case Index of
|
||||
0 : Symbol:='//';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
|
||||
end;
|
||||
ssCommentSuffix :
|
||||
case Index of
|
||||
0 : Symbol:='}';
|
||||
1 : Symbol:='*)';
|
||||
0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
|
||||
1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
|
||||
end;
|
||||
ssStringPrefix :
|
||||
Symbol:='''';
|
||||
GetSpecSymbol:=@FreePascalStringPrefix;
|
||||
ssStringSuffix :
|
||||
Symbol:='''';
|
||||
GetSpecSymbol:=@FreePascalStringSuffix;
|
||||
{ must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
|
||||
ssAsmPrefix :
|
||||
Symbol:='ASM';
|
||||
GetSpecSymbol:=@FreePascalAsmPrefix;
|
||||
ssAsmSuffix :
|
||||
Symbol:='END';
|
||||
GetSpecSymbol:=@FreePascalAsmSuffix;
|
||||
ssDirectivePrefix :
|
||||
Symbol:='{$';
|
||||
GetSpecSymbol:=@FreePascalDirectivePrefix;
|
||||
ssDirectiveSuffix :
|
||||
Symbol:='}';
|
||||
else
|
||||
begin
|
||||
GetSpecSymbol:=false;
|
||||
Symbol:='';
|
||||
end;
|
||||
GetSpecSymbol:=@FreePascalDirectiveSuffix;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -4369,7 +4360,10 @@ end;
|
||||
END.
|
||||
{
|
||||
$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
|
||||
|
||||
Revision 1.30 2002/09/11 10:05:10 pierre
|
||||
|
@ -562,7 +562,7 @@ type
|
||||
public
|
||||
{ Syntax highlight support }
|
||||
{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 IsAsmReservedWord(const S: string): boolean; virtual;
|
||||
public
|
||||
@ -2093,7 +2093,7 @@ var
|
||||
type TPartialType = (pmNone,pmLeft,pmRight,pmAny);
|
||||
|
||||
function MatchesAnySpecSymbol(SClass: TSpecSymbolClass; PartialMatch: TPartialType): boolean;
|
||||
var S: string;
|
||||
var S: pstring;
|
||||
I: Sw_integer;
|
||||
Match,Found: boolean;
|
||||
begin
|
||||
@ -2102,23 +2102,23 @@ var
|
||||
for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
|
||||
begin
|
||||
SymbolIndex:=I;
|
||||
Editor^.GetSpecSymbol(SClass,I-1,S);
|
||||
if (length(SymbolConcat)<length(S)) or
|
||||
((PartialMatch=pmNone) and (length(S)<>length(SymbolConcat)))
|
||||
S:=Editor^.GetSpecSymbol(SClass,I-1);
|
||||
if (length(SymbolConcat)<length(S^)) or
|
||||
((PartialMatch=pmNone) and (length(S^)<>length(SymbolConcat)))
|
||||
then
|
||||
Match:=false
|
||||
else
|
||||
begin
|
||||
case PartialMatch of
|
||||
pmNone : Match:=SymbolConcat=S;
|
||||
pmNone : Match:=SymbolConcat=S^;
|
||||
pmRight:
|
||||
Match:=copy(SymbolConcat,length(SymbolConcat)-length(S)+1,length(S))=S;
|
||||
else Match:=MatchSymbol(SymbolConcat,S);
|
||||
Match:=copy(SymbolConcat,length(SymbolConcat)-length(S^)+1,length(S^))=S^;
|
||||
else Match:=MatchSymbol(SymbolConcat,S^);
|
||||
end;
|
||||
end;
|
||||
if Match then
|
||||
begin
|
||||
MatchingSymbol:=S; Found:=true; Break;
|
||||
MatchingSymbol:=S^; Found:=true; Break;
|
||||
end;
|
||||
end;
|
||||
MatchedSymbol:=MatchedSymbol or Found;
|
||||
@ -2126,7 +2126,8 @@ var
|
||||
end;
|
||||
|
||||
function MatchesAsmSpecSymbol(Const OrigWhat: string; SClass: TSpecSymbolClass): boolean;
|
||||
var What, S: string;
|
||||
var What : String;
|
||||
S: pstring;
|
||||
I: Sw_integer;
|
||||
Match,Found: boolean;
|
||||
begin
|
||||
@ -2136,8 +2137,8 @@ var
|
||||
for I:=1 to Editor^.GetSpecSymbolCount(SClass) do
|
||||
begin
|
||||
SymbolIndex:=I;
|
||||
Editor^.GetSpecSymbol(SClass,I-1,S);
|
||||
if (length(S)<>length(What)) then
|
||||
S:=Editor^.GetSpecSymbol(SClass,I-1);
|
||||
if (length(S^)<>length(What)) then
|
||||
Match:=false
|
||||
else
|
||||
begin
|
||||
@ -2145,7 +2146,7 @@ var
|
||||
S:=UpcaseStr(S); asm symbols need to be uppercased PM }
|
||||
{case PartialMatch of
|
||||
pmNone : }
|
||||
Match:=What=S;
|
||||
Match:=What=S^;
|
||||
{ pmRight:
|
||||
Match:=copy(What,length(What)-length(S)+1,length(S))=S;
|
||||
else Match:=MatchSymbol(What,S);
|
||||
@ -2153,7 +2154,7 @@ var
|
||||
end;
|
||||
if Match then
|
||||
begin
|
||||
MatchingSymbol:=S;
|
||||
MatchingSymbol:=S^;
|
||||
Found:=true;
|
||||
Break;
|
||||
end;
|
||||
@ -2312,7 +2313,7 @@ var
|
||||
procedure ProcessChar(C: char);
|
||||
var CC: TCharClass;
|
||||
EX: Sw_integer;
|
||||
EndComment: string;
|
||||
EndComment: pstring;
|
||||
begin
|
||||
CC:=GetCharClass(C);
|
||||
if ClassStart=X then
|
||||
@ -2376,8 +2377,8 @@ var
|
||||
{ Remove (* from SymbolConcat to avoid problem with (*) PM }
|
||||
{ fixes part of bug 1617 }
|
||||
{ but removed proper directive prefix detection ... }
|
||||
Editor^.GetSpecSymbol(ssCommentSuffix,SymbolIndex,EndComment);
|
||||
if MatchingSymbol[length(MatchingSymbol)]=EndComment[1] then
|
||||
EndComment:=Editor^.GetSpecSymbol(ssCommentSuffix,SymbolIndex);
|
||||
if MatchingSymbol[length(MatchingSymbol)]=EndComment^[1] then
|
||||
Delete(SymbolConcat,1,length(MatchingSymbol));
|
||||
end
|
||||
else if InComment and IsCommentSuffix then
|
||||
@ -3114,11 +3115,10 @@ begin
|
||||
GetSpecSymbolCount:=0;
|
||||
end;
|
||||
|
||||
function TCustomCodeEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer;var Symbol: string):boolean;
|
||||
function TCustomCodeEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
|
||||
begin
|
||||
Abstract;
|
||||
Symbol:='';
|
||||
GetSpecSymbol:=false;
|
||||
GetSpecSymbol:=nil;
|
||||
end;
|
||||
|
||||
function TCustomCodeEditor.IsReservedWord(const S: string): boolean;
|
||||
@ -7179,7 +7179,10 @@ end;
|
||||
END.
|
||||
{
|
||||
$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
|
||||
|
||||
Revision 1.34 2002/09/11 11:23:48 pierre
|
||||
|
Loading…
Reference in New Issue
Block a user