From 349c44dbd037cb881444fdef48f2a1621692738e Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 2 Dec 2024 09:50:46 +1100 Subject: Optimize calculating lines of range to redraw when whole range is on one line. SciLineFromPosition is a binary search over the line indices but LineStart is just indexing so is less expensive. This code may limit performance when updating many positions. --- src/Editor.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index 1c3437b7e..bd5a0b2c1 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -516,10 +516,14 @@ void Editor::RedrawSelMargin(Sci::Line line, bool allAfter) { } PRectangle Editor::RectangleFromRange(Range r, int overlap) { - const Sci::Line minLine = pcs->DisplayFromDoc( - pdoc->SciLineFromPosition(r.First())); - const Sci::Line maxLine = pcs->DisplayLastFromDoc( - pdoc->SciLineFromPosition(r.Last())); + const Sci::Line docLineFirst = pdoc->SciLineFromPosition(r.First()); + const Sci::Line minLine = pcs->DisplayFromDoc(docLineFirst); + Sci::Line docLineLast = docLineFirst; // Common case where range is wholly in one document line + if (r.Last() >= pdoc->LineStart(docLineFirst + 1)) { + // Range covers multiple lines so need last line + docLineLast = pdoc->SciLineFromPosition(r.Last()); + } + const Sci::Line maxLine = pcs->DisplayLastFromDoc(docLineLast); const PRectangle rcClientDrawing = GetClientDrawingRectangle(); PRectangle rc; const int leftTextOverlap = ((xOffset == 0) && (vs.leftMarginWidth > 0)) ? 1 : 0; -- cgit v1.2.3