Skip to content

Commit

Permalink
optim Fold.FindRangeWithPlusAtLine
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-T committed Mar 5, 2020
1 parent b5a5543 commit 666e72b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion atsynedit/atsynedit_ranges.pas
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ function TATSynRanges.FindDeepestRangeContainingLine(ALine: integer;
function TATSynRanges.FindRangeWithPlusAtLine(ALine: integer): integer;
var
a, b, m, dif: integer;
R: PATSynRange;
begin
Result:= -1;
a:= 0;
Expand All @@ -366,7 +367,8 @@ function TATSynRanges.FindRangeWithPlusAtLine(ALine: integer): integer;
if a>b then exit;
m:= (a+b+1) div 2;

dif:= FList.ItemPtr(m)^.Y-ALine;
R:= FList.ItemPtr(m);
dif:= R^.Y-ALine;

if dif<0 then
a:= m+1
Expand All @@ -375,11 +377,20 @@ function TATSynRanges.FindRangeWithPlusAtLine(ALine: integer): integer;
b:= m-1
else
begin
//range at line start?
if R^.X=1 then
begin
if not R^.IsSimple then
Result:= m;
exit;
end;

//find _first_ range which begins at ALine
while (m>0) and (FList.ItemPtr(m-1)^.Y=ALine) do
Dec(m);
if not FList.ItemPtr(m)^.IsSimple then
Result:= m;

exit;
end;
until false;
Expand Down

0 comments on commit 666e72b

Please sign in to comment.