[bugs:#2511] Some doubtful use of `LineLayout::maxLineLength`
Status: open
Group: Bug
Labels: layout Scintilla
Created: Fri Jun 05, 2026 07:30 AM UTC by Zufu Liu
Last Updated: Fri Jun 05, 2026 07:30 AM UTC
Owner: Neil Hodgson
The last character, style and position for LineLayout is at numCharsInLine index, for lineLength = model.pdoc->LineStart(lineNumber + 1) - model.pdoc->LineStart(lineNumber), maxLineLength >= lineLength >= numCharsInLine >= numCharsBeforeEOL.
maxLineLength is growth only (by LineLayout::Resize() method), it's tight to capacity for chars, styles and positions, so it may extremely larger than lineLength (line length with EOL), some code seems to treat it as lineLength.
Inside EditView::StartEndDisplayLine(), the check if (posInLine <= ll->maxLineLength) can (?) be changed into osInLine <= ll->numCharsInLine.
Inside LineLayout::PointFromPosition():
// In case of very long line put x at arbitrary large position
if (posInLine > maxLineLength) {
pt.x = positions[maxLineLength] - positions[LineStart(lines)];
}
when posInLine > numCharsInLine, the result will be negative (positions beyond numCharsInLine are cleared and never write into), the code can be changed to use numCharsInLine:
// In case of very long line put x at arbitrary large position
if (posInLine > numCharsInLine) {
pt.x = positions[numCharsInLine] - positions[LineStart(lines)];
}
LineLayout::ClearPositions(), change maxLineLength to numCharsInLine could speedup word wrap on slow system, note that chars and styles beyond numCharsInLine are not cleared.LineLayoutCache::Retrieve() can be changed to use ReSet() to reset the layout:
if (cache[pos] && !cache[pos]->CanHold(lineNumber, maxChars)) {
//cache[pos].reset();
cache[pos].ReSet(lineNumber, maxChars);
}
Sent from sourceforge.net because scintill...@googlegroups.com is subscribed to https://sourceforge.net/p/scintilla/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/scintilla/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
I'm find these when try to align up maxLineLength to reduce resizing (similar to LineLayoutCache), and check whether it will makes word wrap faster ([feature-requests:#1481]), the gain is tiny (line wraps in random order and resizing count is small).
LineLayout::maxLineLength used to be a hard coded constant =4000. Longer lines were just truncated.Bounding to numCharsInLine seems OK.
No side effect (change to posRet can occur unless posInLine <= ll->numCharsBeforeEOL (3rd clause of if) so the change appears OK. Drop the redundant clause too.
"ClearPositions(), change maxLineLength to numCharsInLine". Leaving dead values is less stable than clearing to 0 and could lead to more subtle bugs that are dependent on history.
"Retrieve() can be changed to use ReSet()". That appears to save a LineLayout allocation so might be worthwhile.
[bugs:#2511] Some doubtful use of `LineLayout::maxLineLength`
Status: open
Group: Bug
Labels: layout Scintilla
Created: Fri Jun 05, 2026 07:30 AM UTC by Zufu Liu
Last Updated: Fri Jun 05, 2026 07:59 AM UTC
Owner: Neil Hodgson
Bounding to n
numCharsInLineseems OK.
will 1 be added like LineLayout::XInLine() ?
XYPOSITION LineLayout::XInLine(Sci::Position index) const noexcept {
// For positions inside line return value from positions
// For positions after line return last position + 1.0
if (index <= numCharsInLine) {
return positions[index];
}
return positions[numCharsInLine] + 1.0;
}
"Retrieve() can be changed to use ReSet()". That appears to save a LineLayout allocation so might be worthwhile.
EditView::FormatRange() can move LineLayout ll out from the loop, and reset it in the loop.
[bugs:#2511] Some doubtful use of `LineLayout::maxLineLength`
Status: open
Group: Bug
Labels: layout Scintilla
Created: Fri Jun 05, 2026 07:30 AM UTC by Zufu Liu
Last Updated: Thu Jun 11, 2026 07:34 AM UTC
Owner: Neil Hodgson
The +1 is about drawing some indicators more visibly and is only ever called from DrawIndicator.
EditView::FormatRange() ... ll out from the loop
It is cleaner to minimize the lifetime of variables and its unlikely avoiding some allocations will be significant here.
[bugs:#2511] Some doubtful use of `LineLayout::maxLineLength`
Status: open
Group: Bug
Labels: layout Scintilla
Created: Fri Jun 05, 2026 07:30 AM UTC by Zufu Liu
Last Updated: Thu Jun 11, 2026 10:04 AM UTC
Owner: Neil Hodgson