| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4util_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | #ifndef QV4UTIL_H | - | ||||||||||||
| 40 | #define QV4UTIL_H | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | // | - | ||||||||||||
| 43 | // W A R N I N G | - | ||||||||||||
| 44 | // ------------- | - | ||||||||||||
| 45 | // | - | ||||||||||||
| 46 | // This file is not part of the Qt API. It exists purely as an | - | ||||||||||||
| 47 | // implementation detail. This header file may change from version to | - | ||||||||||||
| 48 | // version without notice, or even be removed. | - | ||||||||||||
| 49 | // | - | ||||||||||||
| 50 | // We mean it. | - | ||||||||||||
| 51 | // | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | #include "qv4global_p.h" | - | ||||||||||||
| 54 | #include <QtCore/QBitArray> | - | ||||||||||||
| 55 | #include <algorithm> | - | ||||||||||||
| 56 | #include <vector> | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | namespace QV4 { | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | template <typename T> | - | ||||||||||||
| 63 | struct TemporaryAssignment | - | ||||||||||||
| 64 | { | - | ||||||||||||
| 65 | TemporaryAssignment(T &var, const T& temporaryValue) | - | ||||||||||||
| 66 | : variable(var) | - | ||||||||||||
| 67 | , savedValue(var) | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | variable = temporaryValue; | - | ||||||||||||
| 70 | } executed 119771 times by 14 tests: end of blockExecuted by:
| 119771 | ||||||||||||
| 71 | ~TemporaryAssignment() | - | ||||||||||||
| 72 | { | - | ||||||||||||
| 73 | variable = savedValue; | - | ||||||||||||
| 74 | } executed 119680 times by 14 tests: end of blockExecuted by:
| 119680 | ||||||||||||
| 75 | T &variable; | - | ||||||||||||
| 76 | T savedValue; | - | ||||||||||||
| 77 | private: | - | ||||||||||||
| 78 | TemporaryAssignment(const TemporaryAssignment<T>&); | - | ||||||||||||
| 79 | TemporaryAssignment operator=(const TemporaryAssignment<T>&); | - | ||||||||||||
| 80 | }; | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | #if !defined(BROKEN_STD_VECTOR_BOOL_OR_BROKEN_STD_FIND) | - | ||||||||||||
| 83 | // Sanity: | - | ||||||||||||
| 84 | class BitVector | - | ||||||||||||
| 85 | { | - | ||||||||||||
| 86 | std::vector<bool> bits; | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | public: | - | ||||||||||||
| 89 | BitVector(int size = 0, bool value = false) | - | ||||||||||||
| 90 | : bits(size, value) | - | ||||||||||||
| 91 | {} executed 260 times by 24 tests: end of blockExecuted by:
| 260 | ||||||||||||
| 92 | - | |||||||||||||
| 93 | void clear() | - | ||||||||||||
| 94 | { bits = std::vector<bool>(bits.size(), false); } never executed: end of block | 0 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | void reserve(int size) | - | ||||||||||||
| 97 | { bits.reserve(size); } never executed: end of block | 0 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | int size() const | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | Q_ASSERT(bits.size() < INT_MAX); | - | ||||||||||||
| 102 | return static_cast<int>(bits.size()); executed 163328 times by 24 tests: return static_cast<int>(bits.size());Executed by:
| 163328 | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | void resize(int newSize) | - | ||||||||||||
| 106 | { bits.resize(newSize); } never executed: end of block | 0 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | void resize(int newSize, bool newValue) | - | ||||||||||||
| 109 | { bits.resize(newSize, newValue); } executed 470 times by 24 tests: end of blockExecuted by:
| 470 | ||||||||||||
| 110 | - | |||||||||||||
| 111 | void assign(int newSize, bool value) | - | ||||||||||||
| 112 | { bits.assign(newSize, value); } never executed: end of block | 0 | ||||||||||||
| 113 | - | |||||||||||||
| 114 | int findNext(int start, bool value, bool wrapAround) const | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | // The ++operator of std::vector<bool>::iterator in libc++ has a bug when using it on an | - | ||||||||||||
| 117 | // iterator pointing to the last element. It will not be set to ::end(), but beyond | - | ||||||||||||
| 118 | // that. (It will be set to the first multiple of the native word size that is bigger | - | ||||||||||||
| 119 | // than size().) | - | ||||||||||||
| 120 | // | - | ||||||||||||
| 121 | // See http://llvm.org/bugs/show_bug.cgi?id=19663 | - | ||||||||||||
| 122 | // | - | ||||||||||||
| 123 | // The work-around is to calculate the distance, and compare it to the size() to see if it's | - | ||||||||||||
| 124 | // beyond the end, or take the minimum of the distance and the size. | - | ||||||||||||
| 125 | - | |||||||||||||
| 126 | size_t pos = std::distance(bits.begin(), | - | ||||||||||||
| 127 | std::find(bits.begin() + start, bits.end(), value)); | - | ||||||||||||
| 128 | if (wrapAround && pos >= static_cast<size_t>(size()))
| 0-54286 | ||||||||||||
| 129 | pos = std::distance(bits.begin(), never executed: pos = std::distance(bits.begin(), std::find(bits.begin(), bits.begin() + start, value)); | 0 | ||||||||||||
| 130 | std::find(bits.begin(), bits.begin() + start, value)); never executed: pos = std::distance(bits.begin(), std::find(bits.begin(), bits.begin() + start, value)); | 0 | ||||||||||||
| 131 | - | |||||||||||||
| 132 | pos = qMin(pos, static_cast<size_t>(size())); | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | Q_ASSERT(pos <= static_cast<size_t>(size())); | - | ||||||||||||
| 135 | Q_ASSERT(pos < INT_MAX); | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | return static_cast<int>(pos); executed 54286 times by 23 tests: return static_cast<int>(pos);Executed by:
| 54286 | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | bool at(int idx) const | - | ||||||||||||
| 141 | { return bits.at(idx); } never executed: return bits.at(idx); | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | void setBit(int idx) | - | ||||||||||||
| 144 | { bits[idx] = true; } executed 14020 times by 23 tests: end of blockExecuted by:
| 14020 | ||||||||||||
| 145 | - | |||||||||||||
| 146 | void clearBit(int idx) | - | ||||||||||||
| 147 | { bits[idx] = false; } executed 54286 times by 23 tests: end of blockExecuted by:
| 54286 | ||||||||||||
| 148 | }; | - | ||||||||||||
| 149 | #else // Insanity: | - | ||||||||||||
| 150 | class BitVector | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | QBitArray bits; | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | public: | - | ||||||||||||
| 155 | BitVector(int size = 0, bool value = false) | - | ||||||||||||
| 156 | : bits(size, value) | - | ||||||||||||
| 157 | {} | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | void clear() | - | ||||||||||||
| 160 | { bits = QBitArray(bits.size(), false); } | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | void reserve(int size) | - | ||||||||||||
| 163 | { Q_UNUSED(size); } | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | int size() const | - | ||||||||||||
| 166 | { return bits.size(); } | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | void resize(int newSize) | - | ||||||||||||
| 169 | { bits.resize(newSize); } | - | ||||||||||||
| 170 | - | |||||||||||||
| 171 | void resize(int newSize, bool newValue) | - | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 | int oldSize = bits.size(); | - | ||||||||||||
| 174 | bits.resize(newSize); | - | ||||||||||||
| 175 | bits.fill(newValue, oldSize, bits.size()); | - | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | void assign(int newSize, bool value) | - | ||||||||||||
| 179 | { | - | ||||||||||||
| 180 | bits.resize(newSize); | - | ||||||||||||
| 181 | bits.fill(value); | - | ||||||||||||
| 182 | } | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | int findNext(int start, bool value, bool wrapAround) const | - | ||||||||||||
| 185 | { | - | ||||||||||||
| 186 | for (int i = start, ei = size(); i < ei; ++i) { | - | ||||||||||||
| 187 | if (at(i) == value) | - | ||||||||||||
| 188 | return i; | - | ||||||||||||
| 189 | } | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | if (wrapAround) { | - | ||||||||||||
| 192 | for (int i = 0, ei = start; i < ei; ++i) { | - | ||||||||||||
| 193 | if (at(i) == value) | - | ||||||||||||
| 194 | return i; | - | ||||||||||||
| 195 | } | - | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | return size(); | - | ||||||||||||
| 199 | } | - | ||||||||||||
| 200 | - | |||||||||||||
| 201 | bool at(int idx) const | - | ||||||||||||
| 202 | { return bits.at(idx); } | - | ||||||||||||
| 203 | - | |||||||||||||
| 204 | void setBit(int idx) | - | ||||||||||||
| 205 | { bits[idx] = true; } | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | void clearBit(int idx) | - | ||||||||||||
| 208 | { bits[idx] = false; } | - | ||||||||||||
| 209 | }; | - | ||||||||||||
| 210 | #endif | - | ||||||||||||
| 211 | - | |||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | QT_END_NAMESPACE | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | #endif // QV4UTIL_H | - | ||||||||||||
| Source code | Switch to Preprocessed file |