From 10cf4beef4d7293d6d382fe4b3216da48fa87fa1 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sat, 25 Sep 2010 18:02:59 +1000 Subject: Optimization of line layout by minimizing calls in Editor::LayoutLine and avoiding case force processing unless at least one style uses a case force option. --- src/Editor.cxx | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/Editor.cxx') diff --git a/src/Editor.cxx b/src/Editor.cxx index bca458037..836f3919a 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2022,8 +2022,6 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou if (ll->validity == LineLayout::llInvalid) { ll->widthLine = LineLayout::wrapWidthInfinite; ll->lines = 1; - int numCharsInLine = 0; - int numCharsBeforeEOL = 0; if (vstyle.edgeState == EDGE_BACKGROUND) { ll->edgeColumn = pdoc->FindColumn(line, theEdge); if (ll->edgeColumn >= posLineStart) { @@ -2034,24 +2032,30 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou } char styleByte = 0; - int styleMask = pdoc->stylingBitsMask; + const int styleMask = pdoc->stylingBitsMask; ll->styleBitsSet = 0; // Fill base line layout - for (int charInDoc = posLineStart; charInDoc < posLineEnd; charInDoc++) { - char chDoc = pdoc->CharAt(charInDoc); - styleByte = pdoc->StyleAt(charInDoc); + const int lineLength = posLineEnd - posLineStart; + pdoc->GetCharRange(ll->chars, posLineStart, lineLength); + pdoc->GetStyleRange(ll->styles, posLineStart, lineLength); + int numCharsBeforeEOL = lineLength; + while ((numCharsBeforeEOL > 0) && IsEOLChar(ll->chars[numCharsBeforeEOL-1])) { + numCharsBeforeEOL--; + } + const int numCharsInLine = (vstyle.viewEOL) ? lineLength : numCharsBeforeEOL; + for (int charInLine = 0; charInLine < numCharsInLine; charInLine++) { + styleByte = ll->styles[charInLine]; ll->styleBitsSet |= styleByte; - if (vstyle.viewEOL || (!IsEOLChar(chDoc))) { - ll->chars[numCharsInLine] = chDoc; - ll->styles[numCharsInLine] = static_cast(styleByte & styleMask); - ll->indicators[numCharsInLine] = static_cast(styleByte & ~styleMask); - if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseUpper) - ll->chars[numCharsInLine] = static_cast(toupper(chDoc)); - else if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseLower) - ll->chars[numCharsInLine] = static_cast(tolower(chDoc)); - numCharsInLine++; - if (!IsEOLChar(chDoc)) - numCharsBeforeEOL++; + ll->styles[numCharsInLine] = static_cast(styleByte & styleMask); + ll->indicators[numCharsInLine] = static_cast(styleByte & ~styleMask); + } + if (vstyle.someStylesForceCase) { + for (int charInLine = 0; charInLinechars[charInLine]; + if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseUpper) + ll->chars[charInLine] = static_cast(toupper(chDoc)); + else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseLower) + ll->chars[charInLine] = static_cast(tolower(chDoc)); } } ll->xHighlightGuide = 0; -- cgit v1.2.3