aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2024-12-02 09:50:46 +1100
committerNeil <nyamatongwe@gmail.com>2024-12-02 09:50:46 +1100
commit349c44dbd037cb881444fdef48f2a1621692738e (patch)
tree4e28d9de75c4ced57f72d25209d07fc4c6ba836b
parent7ab81a310fdd4f2196034eaecb1d03fbd4ef203c (diff)
downloadscintilla-mirror-349c44dbd037cb881444fdef48f2a1621692738e.tar.gz
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.
-rw-r--r--src/Editor.cxx12
1 files changed, 8 insertions, 4 deletions
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;