mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-10 13:59:20 +02:00
replaced some strings in synedit with faster PChar
git-svn-id: trunk@8370 -
This commit is contained in:
parent
9ff3525add
commit
570abffd09
@ -137,7 +137,7 @@ const
|
|||||||
AllIdentifierDefinitions =
|
AllIdentifierDefinitions =
|
||||||
[ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition];
|
[ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition];
|
||||||
AllPascalTypes =
|
AllPascalTypes =
|
||||||
[ctnClass,ctnClassInterface,
|
[ctnClass,ctnClassInterface,ctnGenericType,ctnSpecialize,
|
||||||
ctnIdentifier,ctnOpenArrayType,ctnRangedArrayType,ctnRecordType,
|
ctnIdentifier,ctnOpenArrayType,ctnRangedArrayType,ctnRecordType,
|
||||||
ctnRecordCase,ctnRecordVariant,
|
ctnRecordCase,ctnRecordVariant,
|
||||||
ctnProcedureType,ctnSetType,ctnRangeType,ctnEnumerationType,
|
ctnProcedureType,ctnSetType,ctnRangeType,ctnEnumerationType,
|
||||||
|
@ -356,7 +356,7 @@ begin
|
|||||||
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
|
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
|
||||||
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);
|
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);
|
||||||
end;
|
end;
|
||||||
Params.NewNode:=FindTypeNodeOfDefinition(Params.NewNode);
|
Params.NewNode:=Params.NewCodeTool.FindTypeNodeOfDefinition(Params.NewNode);
|
||||||
if Params.NewNode.Desc<>ctnProcedureType then begin
|
if Params.NewNode.Desc<>ctnProcedureType then begin
|
||||||
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
|
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
|
||||||
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);
|
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);
|
||||||
|
@ -1818,7 +1818,7 @@ begin
|
|||||||
NewTool.ReadNextAtom;
|
NewTool.ReadNextAtom;
|
||||||
Result:=Result+NewTool.GetAtom;
|
Result:=Result+NewTool.GetAtom;
|
||||||
IdentAdded:=true;
|
IdentAdded:=true;
|
||||||
TypeNode:=FindTypeNodeOfDefinition(NewNode);
|
TypeNode:=NewTool.FindTypeNodeOfDefinition(NewNode);
|
||||||
if TypeNode<>nil then begin
|
if TypeNode<>nil then begin
|
||||||
case TypeNode.Desc of
|
case TypeNode.Desc of
|
||||||
ctnIdentifier, ctnClass, ctnClassInterface:
|
ctnIdentifier, ctnClass, ctnClassInterface:
|
||||||
@ -2840,7 +2840,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (Result.Node.Desc in AllIdentifierDefinitions) then begin
|
if (Result.Node.Desc in AllIdentifierDefinitions) then begin
|
||||||
// instead of variable/const/type definition, return the type
|
// instead of variable/const/type definition, return the type
|
||||||
DummyNode:=FindTypeNodeOfDefinition(Result.Node);
|
DummyNode:=Result.Tool.FindTypeNodeOfDefinition(Result.Node);
|
||||||
if DummyNode=nil then
|
if DummyNode=nil then
|
||||||
// some constants and variants do not have a type
|
// some constants and variants do not have a type
|
||||||
break;
|
break;
|
||||||
@ -3948,7 +3948,7 @@ begin
|
|||||||
ReadNextAtom; // read keyword 'class', 'object', 'interface', 'dispinterface'
|
ReadNextAtom; // read keyword 'class', 'object', 'interface', 'dispinterface'
|
||||||
if UpAtomIs('PACKED') then ReadNextAtom;
|
if UpAtomIs('PACKED') then ReadNextAtom;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
ClassIdentNode:=ClassNode.Parent;
|
ClassIdentNode:=ClassNode.GetNodeOfType(ctnTypeDefinition);
|
||||||
if AtomIsChar('(') then begin
|
if AtomIsChar('(') then begin
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if not AtomIsIdentifier(false) then exit;
|
if not AtomIsIdentifier(false) then exit;
|
||||||
|
@ -2994,13 +2994,10 @@ var
|
|||||||
rcLine, rcToken: TRect;
|
rcLine, rcToken: TRect;
|
||||||
CurLine: integer; // line index for the loop
|
CurLine: integer; // line index for the loop
|
||||||
TokenAccu: record
|
TokenAccu: record
|
||||||
// Note: s is not managed as a string, it will only grow!!!
|
|
||||||
// Never use AppendStr or "+", use Len and MaxLen instead and
|
|
||||||
// copy the string chars directly. This is for efficiency.
|
|
||||||
Len, MaxLen: integer;
|
Len, MaxLen: integer;
|
||||||
CharsBefore: integer;
|
CharsBefore: integer;
|
||||||
PhysicalStartPos, PhysicalEndPos: integer;
|
PhysicalStartPos, PhysicalEndPos: integer;
|
||||||
s: string;
|
p: PChar;
|
||||||
FG, BG: TColor;
|
FG, BG: TColor;
|
||||||
Style: TFontStyles;
|
Style: TFontStyles;
|
||||||
end;
|
end;
|
||||||
@ -3165,7 +3162,7 @@ var
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure PaintToken(
|
procedure PaintToken(
|
||||||
const Token: string;
|
Token: PChar;
|
||||||
TokenLen, // TokenLen is the maximum logical (byte) position for Token
|
TokenLen, // TokenLen is the maximum logical (byte) position for Token
|
||||||
CharsBefore, // CharsBefore tells if Token starts at column one or not
|
CharsBefore, // CharsBefore tells if Token starts at column one or not
|
||||||
FirstPhysical,// FirstPhysical is the physical (screen without scrolling)
|
FirstPhysical,// FirstPhysical is the physical (screen without scrolling)
|
||||||
@ -3193,7 +3190,7 @@ var
|
|||||||
pszText := nil;
|
pszText := nil;
|
||||||
nCharsToPaint := 0;
|
nCharsToPaint := 0;
|
||||||
end else begin
|
end else begin
|
||||||
pszText := PChar(@Token[First]);
|
pszText := @Token[First-1];
|
||||||
nCharsToPaint := Min(Last - First + 1, TokenLen - First + 1);
|
nCharsToPaint := Min(Last - First + 1, TokenLen - First + 1);
|
||||||
ExpandSpecialChars(pszText,nCharsToPaint,FirstPhysical);
|
ExpandSpecialChars(pszText,nCharsToPaint,FirstPhysical);
|
||||||
end;
|
end;
|
||||||
@ -3276,7 +3273,7 @@ var
|
|||||||
SetDrawingColors(FALSE);
|
SetDrawingColors(FALSE);
|
||||||
rcToken.Right := ScreenColumnToXValue(nSelStart);
|
rcToken.Right := ScreenColumnToXValue(nSelStart);
|
||||||
with TokenAccu do
|
with TokenAccu do
|
||||||
PaintToken(s,Len,CharsBefore,C1Phys,nC1,SelStartLogical);
|
PaintToken(p,Len,CharsBefore,C1Phys,nC1,SelStartLogical);
|
||||||
end;
|
end;
|
||||||
// selected part of the token
|
// selected part of the token
|
||||||
SetDrawingColors(TRUE);
|
SetDrawingColors(TRUE);
|
||||||
@ -3286,20 +3283,20 @@ var
|
|||||||
C1SelPhys := Max(nSelStart, C1Phys);
|
C1SelPhys := Max(nSelStart, C1Phys);
|
||||||
C2SelPhys := Min(nSelEnd, C2Phys);
|
C2SelPhys := Min(nSelEnd, C2Phys);
|
||||||
rcToken.Right := ScreenColumnToXValue(C2SelPhys);
|
rcToken.Right := ScreenColumnToXValue(C2SelPhys);
|
||||||
with TokenAccu do PaintToken(s,Len,CharsBefore,C1SelPhys,nC1Sel,nC2Sel);
|
with TokenAccu do PaintToken(p,Len,CharsBefore,C1SelPhys,nC1Sel,nC2Sel);
|
||||||
// second unselected part of the token
|
// second unselected part of the token
|
||||||
if bU2 then begin
|
if bU2 then begin
|
||||||
SetDrawingColors(FALSE);
|
SetDrawingColors(FALSE);
|
||||||
rcToken.Right := ScreenColumnToXValue(C2Phys);
|
rcToken.Right := ScreenColumnToXValue(C2Phys);
|
||||||
with TokenAccu do
|
with TokenAccu do
|
||||||
PaintToken(s,Len,CharsBefore,nSelEnd,SelEndLogical,nC2);
|
PaintToken(p,Len,CharsBefore,nSelEnd,SelEndLogical,nC2);
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
C1Phys := Max(FirstCol, TokenAccu.PhysicalStartPos);
|
C1Phys := Max(FirstCol, TokenAccu.PhysicalStartPos);
|
||||||
C2Phys := Min(LastCol, TokenAccu.PhysicalEndPos+1);
|
C2Phys := Min(LastCol, TokenAccu.PhysicalEndPos+1);
|
||||||
SetDrawingColors(bSel);
|
SetDrawingColors(bSel);
|
||||||
rcToken.Right := ScreenColumnToXValue(C2Phys);
|
rcToken.Right := ScreenColumnToXValue(C2Phys);
|
||||||
with TokenAccu do PaintToken(s, Len, CharsBefore, C1Phys, nC1, nC2);
|
with TokenAccu do PaintToken(p, Len, CharsBefore, C1Phys, nC1, nC2);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3409,10 +3406,10 @@ var
|
|||||||
if bCanAppend then begin
|
if bCanAppend then begin
|
||||||
if (TokenAccu.Len + TokenLen > TokenAccu.MaxLen) then begin
|
if (TokenAccu.Len + TokenLen > TokenAccu.MaxLen) then begin
|
||||||
TokenAccu.MaxLen := TokenAccu.Len + TokenLen + 32;
|
TokenAccu.MaxLen := TokenAccu.Len + TokenLen + 32;
|
||||||
SetLength(TokenAccu.s, TokenAccu.MaxLen);
|
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
|
||||||
end;
|
end;
|
||||||
for i := 1 to TokenLen do begin
|
for i := 0 to TokenLen-1 do begin
|
||||||
TokenAccu.s[TokenAccu.Len + i] := Token[i-1];
|
TokenAccu.p[TokenAccu.Len + i] := Token[i];
|
||||||
end;
|
end;
|
||||||
Inc(TokenAccu.Len, TokenLen);
|
Inc(TokenAccu.Len, TokenLen);
|
||||||
TokenAccu.PhysicalEndPos := PhysicalEndPos;
|
TokenAccu.PhysicalEndPos := PhysicalEndPos;
|
||||||
@ -3420,10 +3417,10 @@ var
|
|||||||
TokenAccu.Len := TokenLen;
|
TokenAccu.Len := TokenLen;
|
||||||
if (TokenAccu.Len > TokenAccu.MaxLen) then begin
|
if (TokenAccu.Len > TokenAccu.MaxLen) then begin
|
||||||
TokenAccu.MaxLen := TokenAccu.Len + 32;
|
TokenAccu.MaxLen := TokenAccu.Len + 32;
|
||||||
SetLength(TokenAccu.s, TokenAccu.MaxLen);
|
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
|
||||||
end;
|
end;
|
||||||
for i := 1 to TokenLen do begin
|
for i := 0 to TokenLen-1 do begin
|
||||||
TokenAccu.s[i] := Token[i-1];
|
TokenAccu.p[i] := Token[i];
|
||||||
end;
|
end;
|
||||||
TokenAccu.CharsBefore := CharsBefore;
|
TokenAccu.CharsBefore := CharsBefore;
|
||||||
TokenAccu.PhysicalStartPos := PhysicalStartPos;
|
TokenAccu.PhysicalStartPos := PhysicalStartPos;
|
||||||
@ -3584,7 +3581,7 @@ var
|
|||||||
// Make sure the token accumulator string doesn't get reassigned to often.
|
// Make sure the token accumulator string doesn't get reassigned to often.
|
||||||
if Assigned(fHighlighter) then begin
|
if Assigned(fHighlighter) then begin
|
||||||
TokenAccu.MaxLen := Max(128, fCharsInWindow * 4);
|
TokenAccu.MaxLen := Max(128, fCharsInWindow * 4);
|
||||||
SetLength(TokenAccu.s, TokenAccu.MaxLen);
|
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
|
||||||
end;
|
end;
|
||||||
// Now loop through all the lines. The indices are valid for Lines.
|
// Now loop through all the lines. The indices are valid for Lines.
|
||||||
CurLine := FirstLine-1;
|
CurLine := FirstLine-1;
|
||||||
@ -3674,22 +3671,22 @@ var
|
|||||||
// paint unselected text in front of selection
|
// paint unselected text in front of selection
|
||||||
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(FirstCol));
|
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(FirstCol));
|
||||||
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelStart));
|
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelStart));
|
||||||
PaintToken(sLine, nTokenLen, 0, FirstCol,
|
PaintToken(PChar(sLine), nTokenLen, 0, FirstCol,
|
||||||
FirstColLogical, SelStartLogical-1);
|
FirstColLogical, SelStartLogical-1);
|
||||||
// paint unselected text behind selection
|
// paint unselected text behind selection
|
||||||
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelEnd));
|
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelEnd));
|
||||||
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(LastCol));
|
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(LastCol));
|
||||||
PaintToken(sLine, nTokenLen, 0, nSelEnd,
|
PaintToken(PChar(sLine), nTokenLen, 0, nSelEnd,
|
||||||
SelEndLogical, LastColLogical);
|
SelEndLogical, LastColLogical);
|
||||||
// paint selection
|
// paint selection
|
||||||
SetDrawingColors(TRUE);
|
SetDrawingColors(TRUE);
|
||||||
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelStart));
|
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelStart));
|
||||||
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelEnd));
|
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelEnd));
|
||||||
PaintToken(sLine, nTokenLen, 0, nSelStart,
|
PaintToken(PChar(sLine), nTokenLen, 0, nSelStart,
|
||||||
SelStartLogical, SelEndLogical-1);
|
SelStartLogical, SelEndLogical-1);
|
||||||
end else begin
|
end else begin
|
||||||
SetDrawingColors(bLineSelected);
|
SetDrawingColors(bLineSelected);
|
||||||
PaintToken(sLine, nTokenLen, 0, FirstCol,
|
PaintToken(PChar(sLine), nTokenLen, 0, FirstCol,
|
||||||
FirstColLogical, LastColLogical);
|
FirstColLogical, LastColLogical);
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
@ -3897,6 +3894,7 @@ var
|
|||||||
ypos : integer;
|
ypos : integer;
|
||||||
begin
|
begin
|
||||||
CurLine:=-1;
|
CurLine:=-1;
|
||||||
|
FillChar(TokenAccu,SizeOf(TokenAccu),0);
|
||||||
//DebugLn('TCustomSynEdit.PaintTextLines ',DbgSName(Self),' TopLine=',dbgs(TopLine));
|
//DebugLn('TCustomSynEdit.PaintTextLines ',DbgSName(Self),' TopLine=',dbgs(TopLine));
|
||||||
colEditorBG := Color;
|
colEditorBG := Color;
|
||||||
if Assigned(Highlighter) and Assigned(Highlighter.WhitespaceAttribute) then
|
if Assigned(Highlighter) and Assigned(Highlighter.WhitespaceAttribute) then
|
||||||
@ -3967,8 +3965,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
PaintCtrlMouseLinkLine;
|
PaintCtrlMouseLinkLine;
|
||||||
|
ReAllocMem(TokenAccu.p,0);
|
||||||
end;
|
end;
|
||||||
{$ELSE below for NOT SYN_LAZARUS ----------------------------------------------}
|
{$ELSE below for NOT SYN_LAZARUS ----------------------------------------------}
|
||||||
var
|
var
|
||||||
@ -10498,20 +10497,22 @@ function TCustomSynEdit.PhysicalToLogicalCol(const Line: string;
|
|||||||
var
|
var
|
||||||
BytePos, ByteLen: integer;
|
BytePos, ByteLen: integer;
|
||||||
ScreenPos: integer;
|
ScreenPos: integer;
|
||||||
|
PLine: PChar;
|
||||||
begin
|
begin
|
||||||
ByteLen := Length(Line);
|
ByteLen := Length(Line);
|
||||||
ScreenPos := StartPhysicalPos;
|
ScreenPos := StartPhysicalPos-1;
|
||||||
BytePos := StartBytePos;
|
BytePos := StartBytePos-1;
|
||||||
|
PLine := PChar(Line);
|
||||||
// map utf and tab chars
|
// map utf and tab chars
|
||||||
while ScreenPos < PhysicalPos do begin
|
while ScreenPos < PhysicalPos do begin
|
||||||
if (BytePos <= ByteLen) then begin
|
if (BytePos <= ByteLen) then begin
|
||||||
if (Line[BytePos] = #9) then begin
|
if (PLine[BytePos] = #9) then begin
|
||||||
inc(ScreenPos, TabWidth - ((ScreenPos-1) mod TabWidth));
|
inc(ScreenPos, TabWidth - ((ScreenPos-1) mod TabWidth));
|
||||||
inc(BytePos);
|
inc(BytePos);
|
||||||
end else begin
|
end else begin
|
||||||
inc(ScreenPos);
|
inc(ScreenPos);
|
||||||
if UseUTF8 then
|
if UseUTF8 then
|
||||||
inc(BytePos,UTF8CharacterLength(@Line[BytePos]))
|
inc(BytePos,UTF8CharacterLength(PLine))
|
||||||
else
|
else
|
||||||
inc(BytePos);
|
inc(BytePos);
|
||||||
end;
|
end;
|
||||||
@ -10522,9 +10523,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if (ScreenPos>PhysicalPos) and (BytePos<=ByteLen-1)
|
if (ScreenPos>PhysicalPos) and (BytePos<=ByteLen-1)
|
||||||
and (Line[BytePos-1]=#9) then
|
and (PLine[BytePos-1]=#9) then
|
||||||
dec(BytePos);
|
dec(BytePos);
|
||||||
Result := BytePos;
|
Result := BytePos+1;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user