replaced some strings in synedit with faster PChar

git-svn-id: trunk@8370 -
This commit is contained in:
mattias 2005-12-26 11:55:57 +00:00
parent 9ff3525add
commit 570abffd09
4 changed files with 34 additions and 33 deletions

View File

@ -137,7 +137,7 @@ const
AllIdentifierDefinitions =
[ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition];
AllPascalTypes =
[ctnClass,ctnClassInterface,
[ctnClass,ctnClassInterface,ctnGenericType,ctnSpecialize,
ctnIdentifier,ctnOpenArrayType,ctnRangedArrayType,ctnRecordType,
ctnRecordCase,ctnRecordVariant,
ctnProcedureType,ctnSetType,ctnRangeType,ctnEnumerationType,

View File

@ -356,7 +356,7 @@ begin
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);
end;
Params.NewNode:=FindTypeNodeOfDefinition(Params.NewNode);
Params.NewNode:=Params.NewCodeTool.FindTypeNodeOfDefinition(Params.NewNode);
if Params.NewNode.Desc<>ctnProcedureType then begin
Params.NewCodeTool.MoveCursorToNodeStart(Params.NewNode);
Params.NewCodeTool.RaiseException(ctsMethodTypeDefinitionNotFound);

View File

@ -1818,7 +1818,7 @@ begin
NewTool.ReadNextAtom;
Result:=Result+NewTool.GetAtom;
IdentAdded:=true;
TypeNode:=FindTypeNodeOfDefinition(NewNode);
TypeNode:=NewTool.FindTypeNodeOfDefinition(NewNode);
if TypeNode<>nil then begin
case TypeNode.Desc of
ctnIdentifier, ctnClass, ctnClassInterface:
@ -2840,7 +2840,7 @@ begin
{$ENDIF}
if (Result.Node.Desc in AllIdentifierDefinitions) then begin
// instead of variable/const/type definition, return the type
DummyNode:=FindTypeNodeOfDefinition(Result.Node);
DummyNode:=Result.Tool.FindTypeNodeOfDefinition(Result.Node);
if DummyNode=nil then
// some constants and variants do not have a type
break;
@ -3948,7 +3948,7 @@ begin
ReadNextAtom; // read keyword 'class', 'object', 'interface', 'dispinterface'
if UpAtomIs('PACKED') then ReadNextAtom;
ReadNextAtom;
ClassIdentNode:=ClassNode.Parent;
ClassIdentNode:=ClassNode.GetNodeOfType(ctnTypeDefinition);
if AtomIsChar('(') then begin
ReadNextAtom;
if not AtomIsIdentifier(false) then exit;

View File

@ -2994,13 +2994,10 @@ var
rcLine, rcToken: TRect;
CurLine: integer; // line index for the loop
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;
CharsBefore: integer;
PhysicalStartPos, PhysicalEndPos: integer;
s: string;
p: PChar;
FG, BG: TColor;
Style: TFontStyles;
end;
@ -3165,7 +3162,7 @@ var
end;
procedure PaintToken(
const Token: string;
Token: PChar;
TokenLen, // TokenLen is the maximum logical (byte) position for Token
CharsBefore, // CharsBefore tells if Token starts at column one or not
FirstPhysical,// FirstPhysical is the physical (screen without scrolling)
@ -3193,7 +3190,7 @@ var
pszText := nil;
nCharsToPaint := 0;
end else begin
pszText := PChar(@Token[First]);
pszText := @Token[First-1];
nCharsToPaint := Min(Last - First + 1, TokenLen - First + 1);
ExpandSpecialChars(pszText,nCharsToPaint,FirstPhysical);
end;
@ -3276,7 +3273,7 @@ var
SetDrawingColors(FALSE);
rcToken.Right := ScreenColumnToXValue(nSelStart);
with TokenAccu do
PaintToken(s,Len,CharsBefore,C1Phys,nC1,SelStartLogical);
PaintToken(p,Len,CharsBefore,C1Phys,nC1,SelStartLogical);
end;
// selected part of the token
SetDrawingColors(TRUE);
@ -3286,20 +3283,20 @@ var
C1SelPhys := Max(nSelStart, C1Phys);
C2SelPhys := Min(nSelEnd, C2Phys);
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
if bU2 then begin
SetDrawingColors(FALSE);
rcToken.Right := ScreenColumnToXValue(C2Phys);
with TokenAccu do
PaintToken(s,Len,CharsBefore,nSelEnd,SelEndLogical,nC2);
PaintToken(p,Len,CharsBefore,nSelEnd,SelEndLogical,nC2);
end;
end else begin
C1Phys := Max(FirstCol, TokenAccu.PhysicalStartPos);
C2Phys := Min(LastCol, TokenAccu.PhysicalEndPos+1);
SetDrawingColors(bSel);
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;
@ -3409,10 +3406,10 @@ var
if bCanAppend then begin
if (TokenAccu.Len + TokenLen > TokenAccu.MaxLen) then begin
TokenAccu.MaxLen := TokenAccu.Len + TokenLen + 32;
SetLength(TokenAccu.s, TokenAccu.MaxLen);
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
end;
for i := 1 to TokenLen do begin
TokenAccu.s[TokenAccu.Len + i] := Token[i-1];
for i := 0 to TokenLen-1 do begin
TokenAccu.p[TokenAccu.Len + i] := Token[i];
end;
Inc(TokenAccu.Len, TokenLen);
TokenAccu.PhysicalEndPos := PhysicalEndPos;
@ -3420,10 +3417,10 @@ var
TokenAccu.Len := TokenLen;
if (TokenAccu.Len > TokenAccu.MaxLen) then begin
TokenAccu.MaxLen := TokenAccu.Len + 32;
SetLength(TokenAccu.s, TokenAccu.MaxLen);
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
end;
for i := 1 to TokenLen do begin
TokenAccu.s[i] := Token[i-1];
for i := 0 to TokenLen-1 do begin
TokenAccu.p[i] := Token[i];
end;
TokenAccu.CharsBefore := CharsBefore;
TokenAccu.PhysicalStartPos := PhysicalStartPos;
@ -3584,7 +3581,7 @@ var
// Make sure the token accumulator string doesn't get reassigned to often.
if Assigned(fHighlighter) then begin
TokenAccu.MaxLen := Max(128, fCharsInWindow * 4);
SetLength(TokenAccu.s, TokenAccu.MaxLen);
ReAllocMem(TokenAccu.p, TokenAccu.MaxLen);
end;
// Now loop through all the lines. The indices are valid for Lines.
CurLine := FirstLine-1;
@ -3674,22 +3671,22 @@ var
// paint unselected text in front of selection
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(FirstCol));
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelStart));
PaintToken(sLine, nTokenLen, 0, FirstCol,
PaintToken(PChar(sLine), nTokenLen, 0, FirstCol,
FirstColLogical, SelStartLogical-1);
// paint unselected text behind selection
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelEnd));
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(LastCol));
PaintToken(sLine, nTokenLen, 0, nSelEnd,
PaintToken(PChar(sLine), nTokenLen, 0, nSelEnd,
SelEndLogical, LastColLogical);
// paint selection
SetDrawingColors(TRUE);
rcToken.Left := Max(rcLine.Left, ScreenColumnToXValue(nSelStart));
rcToken.Right := Min(rcLine.Right, ScreenColumnToXValue(nSelEnd));
PaintToken(sLine, nTokenLen, 0, nSelStart,
PaintToken(PChar(sLine), nTokenLen, 0, nSelStart,
SelStartLogical, SelEndLogical-1);
end else begin
SetDrawingColors(bLineSelected);
PaintToken(sLine, nTokenLen, 0, FirstCol,
PaintToken(PChar(sLine), nTokenLen, 0, FirstCol,
FirstColLogical, LastColLogical);
end;
end else begin
@ -3897,6 +3894,7 @@ var
ypos : integer;
begin
CurLine:=-1;
FillChar(TokenAccu,SizeOf(TokenAccu),0);
//DebugLn('TCustomSynEdit.PaintTextLines ',DbgSName(Self),' TopLine=',dbgs(TopLine));
colEditorBG := Color;
if Assigned(Highlighter) and Assigned(Highlighter.WhitespaceAttribute) then
@ -3967,8 +3965,9 @@ begin
end;
end;
end;
PaintCtrlMouseLinkLine;
ReAllocMem(TokenAccu.p,0);
end;
{$ELSE below for NOT SYN_LAZARUS ----------------------------------------------}
var
@ -10498,20 +10497,22 @@ function TCustomSynEdit.PhysicalToLogicalCol(const Line: string;
var
BytePos, ByteLen: integer;
ScreenPos: integer;
PLine: PChar;
begin
ByteLen := Length(Line);
ScreenPos := StartPhysicalPos;
BytePos := StartBytePos;
ScreenPos := StartPhysicalPos-1;
BytePos := StartBytePos-1;
PLine := PChar(Line);
// map utf and tab chars
while ScreenPos < PhysicalPos do 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(BytePos);
end else begin
inc(ScreenPos);
if UseUTF8 then
inc(BytePos,UTF8CharacterLength(@Line[BytePos]))
inc(BytePos,UTF8CharacterLength(PLine))
else
inc(BytePos);
end;
@ -10522,9 +10523,9 @@ begin
end;
end;
if (ScreenPos>PhysicalPos) and (BytePos<=ByteLen-1)
and (Line[BytePos-1]=#9) then
and (PLine[BytePos-1]=#9) then
dec(BytePos);
Result := BytePos;
Result := BytePos+1;
end;
{$ENDIF}