From 2da74964c08221fba8875a5bb1d4374ee89b86f6 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 6 Apr 2009 09:00:52 +0000 Subject: [PATCH] fixed two scalability problems that made BTextView perform rather slow with large contents: * when searching for tab characters in DrawLine(), we now limit the search to the current line, too (not only the end of the style) - this avoids scanning to the end of large contents repeatedly * there's no need to refresh from the edit location to the end of the content in _DoInsertText(), we only need to refresh the part that has changed git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29960 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index 222c54da77..a3c8a2c5bb 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -3905,7 +3905,7 @@ BTextView::_DoInsertText(const char *inText, int32 inLength, int32 inOffset, const text_run_array *inRuns) { _CancelInputMethod(); - + if (TextLength() + inLength > MaxBytes()) return; @@ -3923,12 +3923,11 @@ BTextView::_DoInsertText(const char *inText, int32 inLength, int32 inOffset, InsertText(inText, inLength, inOffset, inRuns); // offset the caret/selection - //int32 saveStart = fSelStart; - fSelStart += inLength; - fSelEnd += inLength; + fSelStart += inLength; + fClickOffset = fSelEnd = fSelStart; // recalc line breaks and draw the text - _Refresh(inOffset, textLength, true, false); + _Refresh(inOffset, inOffset + inLength, true, true); } @@ -3997,7 +3996,7 @@ BTextView::_DrawLine(BView *view, const int32 &lineNum, view->SetFont(font); view->SetHighColor(*color); - tabChars = numBytes; + tabChars = min_c(numBytes, length); do { foundTab = fText->FindChar(B_TAB, offset, &tabChars); if (foundTab) { @@ -4046,9 +4045,7 @@ BTextView::_DrawLine(BView *view, const int32 &lineNum, } int32 returnedBytes = tabChars; - const char *stringToDraw = fText->GetString(offset, - &returnedBytes); - + const char *stringToDraw = fText->GetString(offset, &returnedBytes); view->SetDrawingMode(textRenderingMode); view->DrawString(stringToDraw, returnedBytes); if (foundTab) { @@ -4064,7 +4061,7 @@ BTextView::_DrawLine(BView *view, const int32 &lineNum, offset += tabChars; length -= tabChars; numBytes -= tabChars; - tabChars = numBytes; + tabChars = min_c(numBytes, length); numTabs = 0; } while (foundTab && tabChars > 0); }