@@ -602,12 +602,12 @@ bool DirectionalDragArea::isWithinTouchCompositionWindow()
602//************************** ActiveTouchesInfo **************************
602//************************** ActiveTouchesInfo **************************
604DirectionalDragArea::ActiveTouchesInfo::ActiveTouchesInfo(const SharedTimeSource &timeSource)
604DirectionalDragArea::ActiveTouchesInfo::ActiveTouchesInfo(const SharedTimeSource &timeSource)
605− : m_timeSource(timeSource)
605+ : m_timeSource(timeSource), m_lastUsedIndex(-1)
607 // Estimate of the maximum number of active touches we might reach.
607 // Estimate of the maximum number of active touches we might reach.
608 // Not a problem if it ends up being an underestimate as this is just
608 // Not a problem if it ends up being an underestimate as this is just
609 // an optimization.
609 // an optimization.
610− reserve(10);
610+ m_vector.resize(3);
613void DirectionalDragArea::ActiveTouchesInfo::update(QTouchEvent *event)
613void DirectionalDragArea::ActiveTouchesInfo::update(QTouchEvent *event)
@@ -630,33 +630,65 @@ void DirectionalDragArea::ActiveTouchesInfo::update(QTouchEvent *event)
631void DirectionalDragArea::ActiveTouchesInfo::addTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
631void DirectionalDragArea::ActiveTouchesInfo::addTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
633− ActiveTouchInfo activeTouchInfo;
633+ ActiveTouchInfo &activeTouchInfo = getEmptySlot();
634 activeTouchInfo.id = touchPoint.id();
634 activeTouchInfo.id = touchPoint.id();
635 activeTouchInfo.startTime = m_timeSource->msecsSinceReference();
635 activeTouchInfo.startTime = m_timeSource->msecsSinceReference();
636− append(activeTouchInfo);
639void DirectionalDragArea::ActiveTouchesInfo::removeTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
638void DirectionalDragArea::ActiveTouchesInfo::removeTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
641− for (int i = 0; i < count(); ++i) {
640+ for (int i = 0; i <= m_lastUsedIndex; ++i) {
642− if (touchPoint.id() == at(i).id) {
641+ if (touchPoint.id() == m_vector.at(i).id) {
643− remove(i);
642+ freeSlot(i);
647 Q_ASSERT(false); // shouldn't reach this point
646 Q_ASSERT(false); // shouldn't reach this point
649+DirectionalDragArea::ActiveTouchInfo &DirectionalDragArea::ActiveTouchesInfo::getEmptySlot()
651+ Q_ASSERT(m_lastUsedIndex < m_vector.size());
653+ // Look for an in-between vacancy first
654+ for (int i = 0; i < m_lastUsedIndex; ++i) {
655+ ActiveTouchInfo &activeTouchInfo = m_vector[i];
656+ if (!activeTouchInfo.isValid()) {
657+ return activeTouchInfo;
662+ if (m_lastUsedIndex >= m_vector.size()) {
663+ m_vector.resize(m_lastUsedIndex + 1);
666+ return m_vector[m_lastUsedIndex];
669+void DirectionalDragArea::ActiveTouchesInfo::freeSlot(int index)
671+ m_vector[index].reset();
672+ if (index == m_lastUsedIndex) {
675+ } while (m_lastUsedIndex >= 0 && !m_vector.at(m_lastUsedIndex).isValid());
650qint64 DirectionalDragArea::ActiveTouchesInfo::mostRecentStartTime()
679qint64 DirectionalDragArea::ActiveTouchesInfo::mostRecentStartTime()
652− Q_ASSERT(count() > 0);
681+ Q_ASSERT(m_lastUsedIndex >= 0);
654− qint64 highestStartTime;
683+ qint64 highestStartTime = m_vector.at(0).startTime;
655− int i = 0;
684+ int i = 1;
657− highestStartTime = at(i).startTime;
686+ const ActiveTouchInfo &activeTouchInfo = m_vector.at(i);
687+ if (activeTouchInfo.isValid() && activeTouchInfo.startTime > highestStartTime) {
688+ highestStartTime = activeTouchInfo.startTime;
659− } while (i < count());
691+ } while (i < m_lastUsedIndex);
661 return highestStartTime;
693 return highestStartTime;