@@ -602,12 +602,12 @@ bool DirectionalDragArea::isWithinTouchCompositionWindow()
602602//************************** ActiveTouchesInfo **************************
603603
604604DirectionalDragArea::ActiveTouchesInfo::ActiveTouchesInfo(const SharedTimeSource &timeSource)
605− : m_timeSource(timeSource)
605+ : m_timeSource(timeSource), m_lastUsedIndex(-1)
606606{
607607 // Estimate of the maximum number of active touches we might reach.
608608 // Not a problem if it ends up being an underestimate as this is just
609609 // an optimization.
610− reserve(10);
610+ m_vector.resize(3);
611611}
612612
613613void DirectionalDragArea::ActiveTouchesInfo::update(QTouchEvent *event)
@@ -630,33 +630,65 @@ void DirectionalDragArea::ActiveTouchesInfo::update(QTouchEvent *event)
630630
631631void DirectionalDragArea::ActiveTouchesInfo::addTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
632632{
633− ActiveTouchInfo activeTouchInfo;
633+ ActiveTouchInfo &activeTouchInfo = getEmptySlot();
634634 activeTouchInfo.id = touchPoint.id();
635635 activeTouchInfo.startTime = m_timeSource->msecsSinceReference();
636− append(activeTouchInfo);
637636}
638637
639638void DirectionalDragArea::ActiveTouchesInfo::removeTouchPoint(const QTouchEvent::TouchPoint &touchPoint)
640639{
641− for (int i = 0; i < count(); ++i) {
642− if (touchPoint.id() == at(i).id) {
643− remove(i);
640+ for (int i = 0; i <= m_lastUsedIndex; ++i) {
641+ if (touchPoint.id() == m_vector.at(i).id) {
642+ freeSlot(i);
644643 return;
645644 }
646645 }
647646 Q_ASSERT(false); // shouldn't reach this point
648647}
649648
649+DirectionalDragArea::ActiveTouchInfo &DirectionalDragArea::ActiveTouchesInfo::getEmptySlot()
650+{
651+ Q_ASSERT(m_lastUsedIndex < m_vector.size());
652+
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;
658+ }
659+ }
660+
661+ ++m_lastUsedIndex;
662+ if (m_lastUsedIndex >= m_vector.size()) {
663+ m_vector.resize(m_lastUsedIndex + 1);
664+ }
665+
666+ return m_vector[m_lastUsedIndex];
667+}
668+
669+void DirectionalDragArea::ActiveTouchesInfo::freeSlot(int index)
670+{
671+ m_vector[index].reset();
672+ if (index == m_lastUsedIndex) {
673+ do {
674+ --m_lastUsedIndex;
675+ } while (m_lastUsedIndex >= 0 && !m_vector.at(m_lastUsedIndex).isValid());
676+ }
677+}
678+
650679qint64 DirectionalDragArea::ActiveTouchesInfo::mostRecentStartTime()
651680{
652− Q_ASSERT(count() > 0);
681+ Q_ASSERT(m_lastUsedIndex >= 0);
653682
654− qint64 highestStartTime;
655− int i = 0;
683+ qint64 highestStartTime = m_vector.at(0).startTime;
684+ int i = 1;
656685 do {
657− highestStartTime = at(i).startTime;
686+ const ActiveTouchInfo &activeTouchInfo = m_vector.at(i);
687+ if (activeTouchInfo.isValid() && activeTouchInfo.startTime > highestStartTime) {
688+ highestStartTime = activeTouchInfo.startTime;
689+ }
658690 ++i;
659− } while (i < count());
691+ } while (i < m_lastUsedIndex);
660692
661693 return highestStartTime;
662694}