SynEdit: Refactor, LengthOfLongestLine

git-svn-id: trunk@25789 -
This commit is contained in:
martin 2010-05-31 00:31:12 +00:00
parent 4ab9eaac1b
commit 0e98a5118a

View File

@ -311,10 +311,8 @@ end;
function TSynEditStringTabExpander.GetLengthOfLongestLine: integer;
var
Line: String;
CharWidths: TPhysicalCharWidths;
n, m: Integer;
//var
i, j: integer;
CharWidths: PPhysicalCharWidth;
i, j, n, m: Integer;
begin
if (fIndexOfLongestLine >= 0) and (fIndexOfLongestLine < Count) then begin
Result := FTabData[fIndexOfLongestLine];
@ -322,8 +320,10 @@ begin
exit;
end;
try
Result := 0;
m := 0;
CharWidths := nil;
for i := 0 to Count - 1 do begin
j := FTabData[i];
if j = LINE_LEN_UNKNOWN then begin
@ -336,10 +336,10 @@ begin
end else begin
n := length(Line);
if n > m then begin
SetLength(CharWidths, n);
ReAllocMem(CharWidths, n * SizeOf(TPhysicalCharWidth));
m := n;
end;
DoGetPhysicalCharWidths(Pchar(Line), n, i, @CharWidths[0]);
DoGetPhysicalCharWidths(Pchar(Line), n, i, CharWidths);
for m := 0 to n-1 do
j := j + CharWidths[m];
@ -357,6 +357,9 @@ begin
fIndexOfLongestLine := i;
end;
end;
finally
ReAllocMem(CharWidths, 0);
end;
end;
end.