mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 20:19:24 +02:00
SynEdit: Initialize "Result" var of managed type (avoid mem re-alloc in case caller passes non-nil). Issue #41461 (see notes).
This commit is contained in:
parent
81493e2a7d
commit
69d65e704d
@ -1156,9 +1156,10 @@ end;
|
|||||||
function TSynEditStrings.GetPhysicalCharWidths(Line: PChar; LineLen,
|
function TSynEditStrings.GetPhysicalCharWidths(Line: PChar; LineLen,
|
||||||
Index: Integer): TPhysicalCharWidths;
|
Index: Integer): TPhysicalCharWidths;
|
||||||
begin
|
begin
|
||||||
SetLength(Result{%H-}, LineLen);
|
Result := nil;
|
||||||
if LineLen = 0 then
|
if LineLen = 0 then
|
||||||
exit;
|
exit;
|
||||||
|
SetLength(Result{%H-}, LineLen);
|
||||||
DoGetPhysicalCharWidths(Line, LineLen, Index, @Result[0]);
|
DoGetPhysicalCharWidths(Line, LineLen, Index, @Result[0]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -459,6 +459,7 @@ end;
|
|||||||
{$IFDEF SYN_MBCSSUPPORT}
|
{$IFDEF SYN_MBCSSUPPORT}
|
||||||
function TSynCustomExporter.ReplaceMBCS(Char1, Char2: char): string;
|
function TSynCustomExporter.ReplaceMBCS(Char1, Char2: char): string;
|
||||||
begin
|
begin
|
||||||
|
Result := '';
|
||||||
SetLength(Result, 2);
|
SetLength(Result, 2);
|
||||||
Result[1] := Char1;
|
Result[1] := Char1;
|
||||||
Result[2] := Char2;
|
Result[2] := Char2;
|
||||||
@ -474,11 +475,12 @@ var
|
|||||||
begin
|
begin
|
||||||
IsSpace := TRUE;
|
IsSpace := TRUE;
|
||||||
if AToken <> '' then begin
|
if AToken <> '' then begin
|
||||||
|
Result := '';
|
||||||
SrcLen := Length(AToken);
|
SrcLen := Length(AToken);
|
||||||
ISrc := 1;
|
ISrc := 1;
|
||||||
DestLen := SrcLen;
|
DestLen := SrcLen;
|
||||||
IDest := 1;
|
IDest := 1;
|
||||||
SetLength(Result{%H-}, DestLen);
|
SetLength(Result, DestLen);
|
||||||
while ISrc <= SrcLen do begin
|
while ISrc <= SrcLen do begin
|
||||||
c := AToken[ISrc];
|
c := AToken[ISrc];
|
||||||
IsSpace := IsSpace and (c = ' ');
|
IsSpace := IsSpace and (c = ' ');
|
||||||
|
@ -1266,8 +1266,9 @@ end;
|
|||||||
|
|
||||||
function TSynEditFoldExportStream.PeakString(ALen: Integer): String;
|
function TSynEditFoldExportStream.PeakString(ALen: Integer): String;
|
||||||
begin
|
begin
|
||||||
|
Result := '';
|
||||||
If not(FPos+ ALen <= FLen) then
|
If not(FPos+ ALen <= FLen) then
|
||||||
exit('');
|
exit;
|
||||||
SetLength(Result, ALen);
|
SetLength(Result, ALen);
|
||||||
if ALen > 0 then
|
if ALen > 0 then
|
||||||
System.Move((FMem + FPos)^, Result[1], ALen);
|
System.Move((FMem + FPos)^, Result[1], ALen);
|
||||||
@ -1284,8 +1285,9 @@ end;
|
|||||||
|
|
||||||
function TSynEditFoldExportStream.ReadString(ALen: Integer): String;
|
function TSynEditFoldExportStream.ReadString(ALen: Integer): String;
|
||||||
begin
|
begin
|
||||||
|
Result := '';
|
||||||
If not(FPos+ ALen <= FLen) then
|
If not(FPos+ ALen <= FLen) then
|
||||||
exit('');
|
exit;
|
||||||
SetLength(Result, ALen);
|
SetLength(Result, ALen);
|
||||||
if ALen > 0 then
|
if ALen > 0 then
|
||||||
System.Move((FMem + FPos)^, Result[1], ALen);
|
System.Move((FMem + FPos)^, Result[1], ALen);
|
||||||
@ -3126,7 +3128,8 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
i := FoldOpenCount(ALine);
|
i := FoldOpenCount(ALine);
|
||||||
SetLength(Result{%H-}, i);
|
Result := nil;
|
||||||
|
SetLength(Result, i);
|
||||||
while i > 0 do begin
|
while i > 0 do begin
|
||||||
dec(i);
|
dec(i);
|
||||||
Result[i] := InfoForFoldAtTextIndex(ALine, i, False, NeedLen);
|
Result[i] := InfoForFoldAtTextIndex(ALine, i, False, NeedLen);
|
||||||
@ -4609,9 +4612,10 @@ var
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Result := Default(TFoldViewNodeInfo);
|
||||||
hl := TSynCustomFoldHighlighter(HighLighter);
|
hl := TSynCustomFoldHighlighter(HighLighter);
|
||||||
if not assigned(hl) then
|
if not assigned(hl) then
|
||||||
exit; // ToDo: Initialize Result
|
exit;
|
||||||
|
|
||||||
nd.LogXStart := 0;
|
nd.LogXStart := 0;
|
||||||
nd.LogXEnd := 0;
|
nd.LogXEnd := 0;
|
||||||
|
@ -914,7 +914,8 @@ procedure TSynSearchDictionary.BuildDictionary;
|
|||||||
memory consumption, since they have 4 continuation bytes (array size 64)
|
memory consumption, since they have 4 continuation bytes (array size 64)
|
||||||
to bring down the average.
|
to bring down the average.
|
||||||
*)
|
*)
|
||||||
SetLength(Result{%H-}, Length(ATerm));
|
Result := '';
|
||||||
|
SetLength(Result, Length(ATerm));
|
||||||
for i := 1 to Length(ATerm) do begin
|
for i := 1 to Length(ATerm) do begin
|
||||||
c := ATerm[i];
|
c := ATerm[i];
|
||||||
if c < #128
|
if c < #128
|
||||||
|
@ -1835,9 +1835,11 @@ function TSynEditSelection.GetSelText : string;
|
|||||||
begin
|
begin
|
||||||
SrcLen := Length(S);
|
SrcLen := Length(S);
|
||||||
DstLen := Index + Count;
|
DstLen := Index + Count;
|
||||||
if SrcLen >= DstLen then
|
if SrcLen >= DstLen then begin
|
||||||
Result := Copy(S, Index, Count)
|
Result := Copy(S, Index, Count);
|
||||||
|
end
|
||||||
else begin
|
else begin
|
||||||
|
Result := '';
|
||||||
SetLength(Result, DstLen);
|
SetLength(Result, DstLen);
|
||||||
P := PChar(Result);
|
P := PChar(Result);
|
||||||
StrPCopy(P, Copy(S, Index, Count));
|
StrPCopy(P, Copy(S, Index, Count));
|
||||||
|
@ -652,10 +652,10 @@ var
|
|||||||
//DebugLn(['GetTextRange StartPos=',dbgs(StartPos),' EndPos=',dbgs(EndPos)]);
|
//DebugLn(['GetTextRange StartPos=',dbgs(StartPos),' EndPos=',dbgs(EndPos)]);
|
||||||
//DebugLn(Lines.Text);
|
//DebugLn(Lines.Text);
|
||||||
|
|
||||||
if EndPos.Y<StartPos.Y then begin
|
Result:='';
|
||||||
Result:='';
|
if EndPos.Y<StartPos.Y then
|
||||||
exit;
|
exit;
|
||||||
end;
|
|
||||||
CurLine:=Lines[StartPos.Y-1];
|
CurLine:=Lines[StartPos.Y-1];
|
||||||
if StartPos.y=EndPos.Y then
|
if StartPos.y=EndPos.Y then
|
||||||
Result:=CurLine
|
Result:=CurLine
|
||||||
|
@ -274,6 +274,7 @@ begin
|
|||||||
l := 0;
|
l := 0;
|
||||||
for i := 0 to length(CharWidths)-1 do
|
for i := 0 to length(CharWidths)-1 do
|
||||||
l := l + (CharWidths[i] and PCWMask);
|
l := l + (CharWidths[i] and PCWMask);
|
||||||
|
Result := '';
|
||||||
SetLength(Result, l);
|
SetLength(Result, l);
|
||||||
|
|
||||||
l := 1;
|
l := 1;
|
||||||
|
@ -559,6 +559,7 @@ begin
|
|||||||
l := 0;
|
l := 0;
|
||||||
for i := 0 to length(CharWidths)-1 do
|
for i := 0 to length(CharWidths)-1 do
|
||||||
l := l + (CharWidths[i] and PCWMask);
|
l := l + (CharWidths[i] and PCWMask);
|
||||||
|
Result := '';
|
||||||
SetLength(Result, l);
|
SetLength(Result, l);
|
||||||
|
|
||||||
l := 1;
|
l := 1;
|
||||||
|
@ -4553,13 +4553,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynPasSyn.GetToken: string;
|
function TSynPasSyn.GetToken: string;
|
||||||
var
|
|
||||||
Len: LongInt;
|
|
||||||
begin
|
begin
|
||||||
Len := Run - fTokenPos;
|
SetString(Result, @fLine[fTokenPos], Run - fTokenPos);
|
||||||
SetLength(Result{%H-},Len);
|
|
||||||
if Len>0 then
|
|
||||||
System.Move(fLine[fTokenPos],Result[1],Len);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPasSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
|
procedure TSynPasSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
|
||||||
|
@ -188,12 +188,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TSynPositionHighlighter.GetToken: string;
|
function TSynPositionHighlighter.GetToken: string;
|
||||||
var
|
|
||||||
Len: LongInt;
|
|
||||||
begin
|
begin
|
||||||
Len := fTokenEnd - fTokenPos;
|
SetString(Result, @fLine[fTokenPos], fTokenEnd - fTokenPos);
|
||||||
SetLength(Result{%H-},Len);
|
|
||||||
System.Move(fLine[fTokenPos],Result[1],Len);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPositionHighlighter.GetTokenEx(out TokenStart: PChar;
|
procedure TSynPositionHighlighter.GetTokenEx(out TokenStart: PChar;
|
||||||
|
@ -958,8 +958,7 @@ var
|
|||||||
begin
|
begin
|
||||||
TCustomSynEdit(FriendEdit).GetHighlighterAttriAtRowColEx(APos, Ctx, FLastContextLine = APos.Y);
|
TCustomSynEdit(FriendEdit).GetHighlighterAttriAtRowColEx(APos, Ctx, FLastContextLine = APos.Y);
|
||||||
FLastContextLine := APos.Y;
|
FLastContextLine := APos.Y;
|
||||||
SetLength(Result{%H-}, SizeOf(Integer));
|
SetString(Result, PChar(@Ctx), SizeOf(Ctx));
|
||||||
PInteger(@Result[1])^ := Ctx;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynPluginSyncroEdit.SetGutterGlyph(const AValue: TBitmap);
|
procedure TSynPluginSyncroEdit.SetGutterGlyph(const AValue: TBitmap);
|
||||||
|
@ -577,6 +577,7 @@ var
|
|||||||
i, j, k: Integer;
|
i, j, k: Integer;
|
||||||
s: String;
|
s: String;
|
||||||
begin
|
begin
|
||||||
|
Result := nil;
|
||||||
SetLength(Result, length(Lines));
|
SetLength(Result, length(Lines));
|
||||||
for i := low(Lines) to high(Lines) do
|
for i := low(Lines) to high(Lines) do
|
||||||
Result[i-low(Lines)] := Lines[i];
|
Result[i-low(Lines)] := Lines[i];
|
||||||
|
@ -81,7 +81,7 @@ end;
|
|||||||
|
|
||||||
function TTestBasicSynEdit.TestLines1: TStringArray;
|
function TTestBasicSynEdit.TestLines1: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 16);
|
SetLength(Result{%H-}, 16);
|
||||||
// 1 6 11 14
|
// 1 6 11 14
|
||||||
Result[0] := 'Some text to test'; //1
|
Result[0] := 'Some text to test'; //1
|
||||||
// 1 5 9
|
// 1 5 9
|
||||||
@ -111,7 +111,7 @@ end;
|
|||||||
|
|
||||||
function TTestBasicSynEdit.TestLines2: TStringArray;
|
function TTestBasicSynEdit.TestLines2: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 7);
|
SetLength(Result{%H-}, 7);
|
||||||
// 1 6 11 14
|
// 1 6 11 14
|
||||||
Result[0] := 'abc def ghi'; // 1
|
Result[0] := 'abc def ghi'; // 1
|
||||||
Result[1] := 'ABC DEF GHI'; // 2
|
Result[1] := 'ABC DEF GHI'; // 2
|
||||||
@ -307,7 +307,7 @@ var
|
|||||||
|
|
||||||
function TestText1: TStringArray;
|
function TestText1: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 4);
|
SetLength(Result{%H-}, 4);
|
||||||
Result[0] := 'abc';
|
Result[0] := 'abc';
|
||||||
Result[1] := 'öbc';
|
Result[1] := 'öbc';
|
||||||
Result[2] := #9'abc';
|
Result[2] := #9'abc';
|
||||||
@ -2378,7 +2378,7 @@ end;
|
|||||||
procedure TTestBasicSynEdit.TestSearchReplace;
|
procedure TTestBasicSynEdit.TestSearchReplace;
|
||||||
function TestText1: TStringArray;
|
function TestText1: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 9);
|
SetLength(Result{%H-}, 9);
|
||||||
Result[0] := 'aaaa';
|
Result[0] := 'aaaa';
|
||||||
Result[1] := 'xx11';
|
Result[1] := 'xx11';
|
||||||
Result[2] := 'cccc';
|
Result[2] := 'cccc';
|
||||||
|
@ -78,7 +78,7 @@ implementation
|
|||||||
|
|
||||||
function CopyArray(a: array of Integer): TIntArray;
|
function CopyArray(a: array of Integer): TIntArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, Length(a));
|
SetLength(Result{%H-}, Length(a));
|
||||||
if Length(a) > 0 then
|
if Length(a) > 0 then
|
||||||
move(a[0], Result[0], Length(a) * SizeOf(a[0]));
|
move(a[0], Result[0], Length(a) * SizeOf(a[0]));
|
||||||
end;
|
end;
|
||||||
@ -279,7 +279,7 @@ end;
|
|||||||
|
|
||||||
function TTestMarkupFoldColoring.TestText1: TStringArray;
|
function TTestMarkupFoldColoring.TestText1: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 26);
|
SetLength(Result{%H-}, 26);
|
||||||
Result[ 0] := 'program Foo;';
|
Result[ 0] := 'program Foo;';
|
||||||
Result[ 1] := '';
|
Result[ 1] := '';
|
||||||
Result[ 2] := 'procedure a;';
|
Result[ 2] := 'procedure a;';
|
||||||
@ -310,7 +310,7 @@ end;
|
|||||||
|
|
||||||
function TTestMarkupFoldColoring.TestText2: TStringArray;
|
function TTestMarkupFoldColoring.TestText2: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 20);
|
SetLength(Result{%H-}, 20);
|
||||||
Result[0] := 'program a;';
|
Result[0] := 'program a;';
|
||||||
Result[1] := 'procedure TEditorFrame.NotifChanged(Sender: TObject);';
|
Result[1] := 'procedure TEditorFrame.NotifChanged(Sender: TObject);';
|
||||||
Result[2] := 'begin';
|
Result[2] := 'begin';
|
||||||
@ -337,7 +337,7 @@ function TTestMarkupFoldColoring.TestTextEditIfThen(out ExpLines,
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 29);
|
SetLength(Result{%H-}, 29);
|
||||||
SetLength(ExpLines, 29);
|
SetLength(ExpLines, 29);
|
||||||
SetLength(ExpLinesEdited, 18); // stop at bad line // HL may change....
|
SetLength(ExpLinesEdited, 18); // stop at bad line // HL may change....
|
||||||
Result[ 0] := 'program a;';
|
Result[ 0] := 'program a;';
|
||||||
@ -405,7 +405,7 @@ end;
|
|||||||
|
|
||||||
function TTestMarkupFoldColoring.TestTextMultiLineIfIndent: TStringArray;
|
function TTestMarkupFoldColoring.TestTextMultiLineIfIndent: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 29);
|
SetLength(Result{%H-}, 29);
|
||||||
Result[ 0] := 'program a;';
|
Result[ 0] := 'program a;';
|
||||||
Result[ 1] := 'procedure foo;';
|
Result[ 1] := 'procedure foo;';
|
||||||
Result[ 2] := 'begin';
|
Result[ 2] := 'begin';
|
||||||
@ -439,7 +439,7 @@ end;
|
|||||||
|
|
||||||
function TTestMarkupFoldColoring.TestTextInval1: TStringArray;
|
function TTestMarkupFoldColoring.TestTextInval1: TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 20);
|
SetLength(Result{%H-}, 20);
|
||||||
Result[0] := 'procedure';
|
Result[0] := 'procedure';
|
||||||
Result[1] := 'begin';
|
Result[1] := 'begin';
|
||||||
Result[2] := '';
|
Result[2] := '';
|
||||||
@ -466,7 +466,7 @@ function TTestMarkupFoldColoring.TestTextScroll1: TStringArray;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 112);
|
SetLength(Result{%H-}, 112);
|
||||||
Result[0] := 'unit TestUnit;';
|
Result[0] := 'unit TestUnit;';
|
||||||
Result[1] := '';
|
Result[1] := '';
|
||||||
Result[2] := '{$mode objfpc}{$H+}';
|
Result[2] := '{$mode objfpc}{$H+}';
|
||||||
@ -517,7 +517,7 @@ end;
|
|||||||
function TTestMarkupFoldColoring.TestTextCaseScroll1(out
|
function TTestMarkupFoldColoring.TestTextCaseScroll1(out
|
||||||
ExpLines: TTestLineMarkupResults): TStringArray;
|
ExpLines: TTestLineMarkupResults): TStringArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, 44+30);
|
SetLength(Result{%H-}, 44+30);
|
||||||
SetLength(ExpLines, 44);
|
SetLength(ExpLines, 44);
|
||||||
Result[ 0] := 'program a;';
|
Result[ 0] := 'program a;';
|
||||||
Result[ 1] := 'begin';
|
Result[ 1] := 'begin';
|
||||||
|
@ -190,7 +190,7 @@ function FillArray(AFrom, ATo: integer; AIncrease: Integer = 1): TIntArray;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, ATo - AFrom + 1);
|
SetLength(Result{%H-}, ATo - AFrom + 1);
|
||||||
for i := 0 to high(Result) do
|
for i := 0 to high(Result) do
|
||||||
Result[i] := AFrom + i * AIncrease;
|
Result[i] := AFrom + i * AIncrease;
|
||||||
end;
|
end;
|
||||||
@ -210,7 +210,7 @@ function ViewedExp(AFirstViewedIdx: TLineIdx;
|
|||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, Length(ALines));
|
SetLength(Result{%H-}, Length(ALines));
|
||||||
j := 0;
|
j := 0;
|
||||||
for i := 0 to Length(ALines) - 1 do begin
|
for i := 0 to Length(ALines) - 1 do begin
|
||||||
if (i > 0) and (ALines[i].SubIdx = 0) then begin
|
if (i > 0) and (ALines[i].SubIdx = 0) then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user