From 3ea8faca3a3533ab7bf1a23452e2527e880f2659 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 12 Oct 2016 14:18:02 +0300 Subject: QQuickTextInput: replace QString::left with QString::leftRef Reduce memory allocations. While touching the code, port index-based loop to C++11 range-for loop. Change-Id: I7b11f463177f1355fc8be2b44c7a45a82ba1610c Reviewed-by: Ulf Hermann --- src/quick/items/qquicktextinput.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 68112461b2..4c9a1f8dfc 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3687,9 +3687,10 @@ void QQuickTextInputPrivate::internalInsert(const QString &s) } else { int remaining = m_maxLength - m_text.length(); if (remaining != 0) { - m_text.insert(m_cursor, s.left(remaining)); - for (int i = 0; i < s.leftRef(remaining).length(); ++i) - addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1)); + const QStringRef remainingStr = s.leftRef(remaining); + m_text.insert(m_cursor, remainingStr); + for (auto e : remainingStr) + addCommand(Command(Insert, m_cursor++, e, -1, -1)); m_textDirty = true; } } -- cgit v1.2.3