summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextengine.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-05-19 05:18:27 (GMT)
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-08-24 13:08:33 (GMT)
commitacf678e57ed088f3e56a551cac6c7c3322005750 (patch)
tree7211ba7ef5b95b69a71bac9a920760e2dc4fd0ab /src/gui/text/qtextengine.cpp
parent033b53a02fb02c5aec412e3d87ad9661110c6e6e (diff)
downloadQt-acf678e57ed088f3e56a551cac6c7c3322005750.zip
Qt-acf678e57ed088f3e56a551cac6c7c3322005750.tar.gz
Qt-acf678e57ed088f3e56a551cac6c7c3322005750.tar.bz2
Use binarysort to find items.
Task: http://bugreports.qt.nokia.com/browse/QTBUG-231 Reviwed-by: Eskil
Diffstat (limited to 'src/gui/text/qtextengine.cpp')
-rw-r--r--src/gui/text/qtextengine.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 5670e29..8d6dd6c 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1561,14 +1561,19 @@ bool QTextEngine::isRightToLeft() const
int QTextEngine::findItem(int strPos) const
{
itemize();
-
- // ##### use binary search
- int item;
- for (item = layoutData->items.size()-1; item > 0; --item) {
- if (layoutData->items[item].position <= strPos)
- break;
+ 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;
+ }
}
- return item;
+ return right;
}
QFixed QTextEngine::width(int from, int len) const