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);
}
I'm find these when try to align up
maxLineLengthto reduce resizing (similar toLineLayoutCache), 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).Related
Feature Requests: #1481
(Edit: Posting this renumbered all the items, so the pieces here match the above in order (2,1,3,4). )
LineLayout::maxLineLengthused to be a hard coded constant =4000. Longer lines were just truncated.Bounding to
numCharsInLineseems OK.No side effect (change to
posRetcan occur unlessposInLine <= 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
LineLayoutallocation so might be worthwhile.Last edit: Neil Hodgson 1 day ago
will 1 be added like
LineLayout::XInLine()?EditView::FormatRange()can moveLineLayout llout from the loop, and reset it in the loop.The +1 is about drawing some indicators more visibly and is only ever called from
DrawIndicator.It is cleaner to minimize the lifetime of variables and its unlikely avoiding some allocations will be significant here.