Add a version of BitVector that uses QBitArray.
authorErik Verbruggen <erik.verbruggen@digia.com>
Fri, 5 Jun 2015 10:54:36 +0000 (12:54 +0200)
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>
Mon, 8 Jun 2015 08:22:02 +0000 (08:22 +0000)
Some C++ STL libraries are unable to ship a bug-free std::vector<bool>,
and/or a bug-free specialization of std::find for std::vector<bool>. So,
for those platforms there now is a slow version of BitVector, which
relies on QBitArray, which we can fix if we find bugs.

Change-Id: I5ddfb18cabe82049a7ede6083fe6ba142bca068b
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/compiler/qv4ssa.cpp

index 5829e1c813e85efdaa7b34f3c7cc640f43774bfb..e61a602e64c5a3f236d956c31863c7e22fb1d114 100644 (file)
@@ -81,6 +81,8 @@ static void showMeTheCode(IR::Function *function, const char *marker)
     }
 }
 
+#if !defined(BROKEN_STD_VECTOR_BOOL_OR_BROKEN_STD_FIND)
+// Sanity:
 class BitVector
 {
     std::vector<bool> bits;
@@ -140,6 +142,58 @@ public:
     void clearBit(int idx)
     { bits[idx] = false; }
 };
+#else // Insanity:
+class BitVector
+{
+    QBitArray bits;
+
+public:
+    BitVector(int size = 0, bool value = false)
+        : bits(size, value)
+    {}
+
+    void reserve(int size)
+    { Q_UNUSED(size); }
+
+    int size() const
+    { return bits.size(); }
+
+    void resize(int newSize)
+    { bits.resize(newSize); }
+
+    void assign(int newSize, bool value)
+    {
+        bits.resize(newSize);
+        bits.fill(value);
+    }
+
+    int findNext(int start, bool value, bool wrapAround) const
+    {
+        for (int i = start, ei = size(); i < ei; ++i) {
+            if (at(i) == value)
+                return i;
+        }
+
+        if (wrapAround) {
+            for (int i = 0, ei = start; i < ei; ++i) {
+                if (at(i) == value)
+                    return i;
+            }
+        }
+
+        return size();
+    }
+
+    bool at(int idx) const
+    { return bits.at(idx); }
+
+    void setBit(int idx)
+    { bits[idx] = true; }
+
+    void clearBit(int idx)
+    { bits[idx] = false; }
+};
+#endif
 
 class ProcessedBlocks
 {