Use a QVector instead of a QList
authorLars Knoll <lars.knoll@digia.com>
Wed, 2 Oct 2013 13:14:45 +0000 (15:14 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 3 Oct 2013 06:52:11 +0000 (08:52 +0200)
This makes the code go quite a bit faster (saves ~7-8% of the
total amount of instructions executed when running crypto.js

Change-Id: I6b3bd08eca98b45593262e2fc6e0ce5056257e76
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/compiler/qv4isel_moth.cpp
src/qml/compiler/qv4regalloc.cpp
src/qml/compiler/qv4regalloc_p.h
src/qml/compiler/qv4ssa.cpp
src/qml/compiler/qv4ssa_p.h

index 4bea632..7c999ed 100644 (file)
@@ -149,7 +149,7 @@ class QQmlJS::Moth::StackSlotAllocator
     QHash<V4IR::Temp, V4IR::LifeTimeInterval> _intervals;
 
 public:
-    StackSlotAllocator(const QList<V4IR::LifeTimeInterval> &ranges, int maxTempCount)
+    StackSlotAllocator(const QVector<V4IR::LifeTimeInterval> &ranges, int maxTempCount)
         : _activeSlots(maxTempCount)
     {
         _intervals.reserve(ranges.size());
index 7fd5864..58c84ad 100644 (file)
@@ -589,7 +589,7 @@ using namespace QT_PREPEND_NAMESPACE(QQmlJS);
 
 namespace {
 class ResolutionPhase: protected StmtVisitor, protected ExprVisitor {
-    QList<LifeTimeInterval> _intervals;
+    QVector<LifeTimeInterval> _intervals;
     Function *_function;
     RegAllocInfo *_info;
     const QHash<V4IR::Temp, int> &_assignedSpillSlots;
@@ -605,7 +605,7 @@ class ResolutionPhase: protected StmtVisitor, protected ExprVisitor {
     QHash<BasicBlock *, QList<LifeTimeInterval> > _liveAtEnd;
 
 public:
-    ResolutionPhase(const QList<LifeTimeInterval> &intervals, Function *function, RegAllocInfo *info,
+    ResolutionPhase(const QVector<LifeTimeInterval> &intervals, Function *function, RegAllocInfo *info,
                     const QHash<V4IR::Temp, int> &assignedSpillSlots,
                     const QVector<int> &intRegs, const QVector<int> &fpRegs)
         : _intervals(intervals)
@@ -709,7 +709,7 @@ private:
                     break;
                 if (i.temp() == *phi->targetTemp) {
                     activate(i);
-                    _intervals.removeAt(it);
+                    _intervals.remove(it);
                     break;
                 }
             }
@@ -1073,10 +1073,10 @@ void RegisterAllocator::linearScan()
             if (it.end() < position) {
                 if (!it.isFixedInterval())
                     _handled += it;
-                _active.removeAt(i);
+                _active.remove(i);
             } else if (!it.covers(position)) {
                 _inactive += it;
-                _active.removeAt(i);
+                _active.remove(i);
             } else {
                 ++i;
             }
@@ -1088,11 +1088,11 @@ void RegisterAllocator::linearScan()
             if (it.end() < position) {
                 if (!it.isFixedInterval())
                     _handled += it;
-                _inactive.removeAt(i);
+                _inactive.remove(i);
             } else if (it.covers(position)) {
                 if (it.reg() != LifeTimeInterval::Invalid) {
                     _active += it;
-                    _inactive.removeAt(i);
+                    _inactive.remove(i);
                 } else {
                     // although this interval is now active, it has no register allocated (always
                     // spilled), so leave it in inactive.
@@ -1380,7 +1380,7 @@ int RegisterAllocator::nextUse(const Temp &t, int startPosition) const
     return -1;
 }
 
-static inline void insertSorted(QList<LifeTimeInterval> &intervals, const LifeTimeInterval &newInterval)
+static inline void insertSorted(QVector<LifeTimeInterval> &intervals, const LifeTimeInterval &newInterval)
 {
     for (int i = 0, ei = intervals.size(); i != ei; ++i) {
         if (LifeTimeInterval::lessThan(newInterval, intervals.at(i))) {
index 40e88c1..53d09f6 100644 (file)
@@ -64,7 +64,7 @@ class RegisterAllocator
 
     QVector<LifeTimeInterval> _fixedRegisterRanges, _fixedFPRegisterRanges;
 
-    QList<LifeTimeInterval> _unhandled, _active, _inactive, _handled;
+    QVector<LifeTimeInterval> _unhandled, _active, _inactive, _handled;
 
     QHash<V4IR::Temp, int> _lastAssignedRegister;
     QHash<V4IR::Temp, int> _assignedSpillSlots;
index 0462874..6ad9a57 100644 (file)
@@ -2630,7 +2630,7 @@ class LifeRanges {
 
     QHash<BasicBlock *, LiveRegs> _liveIn;
     QHash<Temp, LifeTimeInterval> _intervals;
-    QList<LifeTimeInterval> _sortedRanges;
+    QVector<LifeTimeInterval> _sortedRanges;
 
 public:
     LifeRanges(Function *function, const QHash<BasicBlock *, BasicBlock *> &startEndLoops)
@@ -2659,7 +2659,7 @@ public:
         std::sort(_sortedRanges.begin(), _sortedRanges.end(), LifeTimeInterval::lessThan);
     }
 
-    QList<LifeTimeInterval> ranges() const { return _sortedRanges; }
+    QVector<LifeTimeInterval> ranges() const { return _sortedRanges; }
 
     void dump() const
     {
@@ -2966,7 +2966,7 @@ void Optimizer::convertOutOfSSA() {
     }
 }
 
-QList<LifeTimeInterval> Optimizer::lifeRanges() const
+QVector<LifeTimeInterval> Optimizer::lifeRanges() const
 {
     Q_ASSERT(isInSSA());
 
index 7b4cce8..ceaef9f 100644 (file)
@@ -63,7 +63,7 @@ public:
 
         bool covers(int position) const { return start <= position && position <= end; }
     };
-    typedef QList<Range> Ranges;
+    typedef QVector<Range> Ranges;
 
 private:
     Temp _temp;
@@ -139,7 +139,7 @@ public:
 
     QHash<BasicBlock *, BasicBlock *> loopStartEndBlocks() const { return startEndLoops; }
 
-    QList<LifeTimeInterval> lifeRanges() const;
+    QVector<LifeTimeInterval> lifeRanges() const;
 
     static void showMeTheCode(Function *function);
 
@@ -184,6 +184,11 @@ private:
 
 } // V4IR namespace
 } // QQmlJS namespace
+
+
+Q_DECLARE_TYPEINFO(QQmlJS::V4IR::LifeTimeInterval, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QQmlJS::V4IR::LifeTimeInterval::Range, Q_PRIMITIVE_TYPE);
+
 QT_END_NAMESPACE
 
 #endif // QV4SSA_P_H