From 22995948cd3f46780be5d8016708aeef0cd7b066 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 28 Jul 2011 14:15:28 +0200 Subject: Revert binary search in QTextEngine::findItem It's part of c9607f069f0fb98021daf0af9f1d1b2981018e0c which caused crash in certain cases. Task-number: QTBUG-17209 Reviewed-by: Gunnar Sletta --- src/gui/text/qtextengine.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 6c13eae..cff3641 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1577,19 +1577,13 @@ bool QTextEngine::isRightToLeft() const int QTextEngine::findItem(int strPos) const { itemize(); - int left = 0; - int right = layoutData->items.size()-1; - while(left <= right) { - int middle = ((right-left)/2)+left; - if (strPos > layoutData->items[middle].position) - left = middle+1; - else if(strPos < layoutData->items[middle].position) - right = middle-1; - else { - return middle; - } + + int item; + for (item = layoutData->items.size()-1; item > 0; --item) { + if (layoutData->items[item].position <= strPos) + break; } - return right; + return item; } QFixed QTextEngine::width(int from, int len) const -- cgit v0.12