From 1e17db8ac67612bd9372561d02a20a77e1d9fcf1 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 28 Sep 2006 13:28:13 +0000 Subject: [PATCH] put common code for Insert() methods into DoInsertText(), this avoids an extra strlen() call git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18968 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextView.cpp | 57 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index b4ba4b35bc..0da1d0a7d6 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -1083,16 +1083,17 @@ void BTextView::Insert(const char *inText, const text_run_array *inRuns) { if (inText != NULL) - Insert(fSelStart, inText, strlen(inText), inRuns); + DoInsertText(inText, strlen(inText), fSelStart, inRuns, NULL); } void -BTextView::Insert(const char *inText, int32 inLength, - const text_run_array *inRuns) +BTextView::Insert(const char *inText, int32 inLength, const text_run_array *inRuns) { - if (inText != NULL) - Insert(fSelStart, inText, inLength, inRuns); + if (inText != NULL && inLength > 0) { + int32 realLength = strlen(inText); + DoInsertText(inText, min_c(inLength, realLength), fSelStart, inRuns, NULL); + } } @@ -1102,29 +1103,11 @@ BTextView::Insert(int32 startOffset, const char *inText, int32 inLength, { CALLED(); - CancelInputMethod(); - // do we really need to do anything? - if (inText == NULL || inLength < 1) - return; - - int32 realLength = strlen(inText); - if (inLength > realLength) - inLength = realLength; - - if (startOffset > TextLength()) - startOffset = TextLength(); - - // copy data into buffer - InsertText(inText, inLength, startOffset, inRuns); - - // offset the caret/selection - int32 saveStart = fSelStart; - fSelStart += inLength; - fSelEnd += inLength; - - // recalc line breaks and draw the text - Refresh(saveStart, fSelEnd, true, false); + if (inText != NULL && inLength > 0) { + int32 realLength = strlen(inText); + DoInsertText(inText, min_c(inLength, realLength), startOffset, inRuns, NULL); + } } @@ -3503,7 +3486,25 @@ void BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset, const text_run_array *inRuns, _BTextChangeResult_ *outResult) { - CALLED(); + CancelInputMethod(); + + // Don't do any check, the public methods will have adjusted + // eventual bogus values... + + int32 textLength = TextLength(); + if (inOffset > textLength) + inOffset = textLength; + + // copy data into buffer + InsertText(inText, inLength, inOffset, inRuns); + + // offset the caret/selection + int32 saveStart = fSelStart; + fSelStart += inLength; + fSelEnd += inLength; + + // recalc line breaks and draw the text + Refresh(saveStart, fSelEnd, true, false); }