| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/parser/qqmljsmemorypool_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 | - | |||||||
| 40 | #ifndef QQMLJSMEMORYPOOL_P_H | - | ||||||
| 41 | #define QQMLJSMEMORYPOOL_P_H | - | ||||||
| 42 | - | |||||||
| 43 | // | - | ||||||
| 44 | // W A R N I N G | - | ||||||
| 45 | // ------------- | - | ||||||
| 46 | // | - | ||||||
| 47 | // This file is not part of the Qt API. It exists purely as an | - | ||||||
| 48 | // implementation detail. This header file may change from version to | - | ||||||
| 49 | // version without notice, or even be removed. | - | ||||||
| 50 | // | - | ||||||
| 51 | // We mean it. | - | ||||||
| 52 | // | - | ||||||
| 53 | - | |||||||
| 54 | #include "qqmljsglobal_p.h" | - | ||||||
| 55 | - | |||||||
| 56 | #include <QtCore/qglobal.h> | - | ||||||
| 57 | #include <QtCore/qshareddata.h> | - | ||||||
| 58 | #include <QtCore/qdebug.h> | - | ||||||
| 59 | - | |||||||
| 60 | #include <cstring> | - | ||||||
| 61 | - | |||||||
| 62 | QT_QML_BEGIN_NAMESPACE | - | ||||||
| 63 | - | |||||||
| 64 | namespace QQmlJS { | - | ||||||
| 65 | - | |||||||
| 66 | class Managed; | - | ||||||
| 67 | - | |||||||
| 68 | class QML_PARSER_EXPORT MemoryPool : public QSharedData | - | ||||||
| 69 | { | - | ||||||
| 70 | MemoryPool(const MemoryPool &other); | - | ||||||
| 71 | void operator =(const MemoryPool &other); | - | ||||||
| 72 | - | |||||||
| 73 | public: | - | ||||||
| 74 | MemoryPool() {} | - | ||||||
| 75 | - | |||||||
| 76 | ~MemoryPool() | - | ||||||
| 77 | { | - | ||||||
| 78 | if (_blocks) {
| 560718-2416022 | ||||||
| 79 | for (int i = 0; i < _allocatedBlocks; ++i) {
| 2416218-19423018 | ||||||
| 80 | if (char *b = _blocks[i])
| 2752922-16670454 | ||||||
| 81 | free(b); executed 2752903 times by 148 tests: free(b);Executed by:
| 2752903 | ||||||
| 82 | } executed 19422840 times by 148 tests: end of blockExecuted by:
| 19422840 | ||||||
| 83 | - | |||||||
| 84 | free(_blocks); | - | ||||||
| 85 | } executed 2416169 times by 148 tests: end of blockExecuted by:
| 2416169 | ||||||
| 86 | qDeleteAll(strings); | - | ||||||
| 87 | } executed 2977095 times by 149 tests: end of blockExecuted by:
| 2977095 | ||||||
| 88 | - | |||||||
| 89 | inline void *allocate(size_t size) | - | ||||||
| 90 | { | - | ||||||
| 91 | size = (size + 7) & ~7; | - | ||||||
| 92 | if (Q_LIKELY(_ptr && (_ptr + size < _end))) {
| 2748904-69163266 | ||||||
| 93 | void *addr = _ptr; | - | ||||||
| 94 | _ptr += size; | - | ||||||
| 95 | return addr; executed 69167663 times by 148 tests: return addr;Executed by:
| 69167663 | ||||||
| 96 | } | - | ||||||
| 97 | return allocate_helper(size); executed 2748849 times by 148 tests: return allocate_helper(size);Executed by:
| 2748849 | ||||||
| 98 | } | - | ||||||
| 99 | - | |||||||
| 100 | void reset() | - | ||||||
| 101 | { | - | ||||||
| 102 | _blockCount = -1; | - | ||||||
| 103 | _ptr = _end = nullptr; | - | ||||||
| 104 | } never executed: end of block | 0 | ||||||
| 105 | - | |||||||
| 106 | template <typename Tp> Tp *New() { return new (this->allocate(sizeof(Tp))) Tp(); } executed 2102 times by 36 tests: return new (this->allocate(sizeof(Tp))) Tp();Executed by:
| 2102 | ||||||
| 107 | - | |||||||
| 108 | QStringRef newString(const QString &string) { | - | ||||||
| 109 | strings.append(new QString(string)); | - | ||||||
| 110 | return QStringRef(strings.last()); executed 16502 times by 10 tests: return QStringRef(strings.last());Executed by:
| 16502 | ||||||
| 111 | } | - | ||||||
| 112 | - | |||||||
| 113 | private: | - | ||||||
| 114 | Q_NEVER_INLINE void *allocate_helper(size_t size) | - | ||||||
| 115 | { | - | ||||||
| 116 | Q_ASSERT(size < BLOCK_SIZE); | - | ||||||
| 117 | - | |||||||
| 118 | if (++_blockCount == _allocatedBlocks) {
| 326655-2424037 | ||||||
| 119 | if (! _allocatedBlocks)
| 9629-2413812 | ||||||
| 120 | _allocatedBlocks = DEFAULT_BLOCK_COUNT; executed 2414226 times by 148 tests: _allocatedBlocks = DEFAULT_BLOCK_COUNT;Executed by:
| 2414226 | ||||||
| 121 | else | - | ||||||
| 122 | _allocatedBlocks *= 2; executed 9622 times by 18 tests: _allocatedBlocks *= 2;Executed by:
| 9622 | ||||||
| 123 | - | |||||||
| 124 | _blocks = (char **) realloc(_blocks, sizeof(char *) * _allocatedBlocks); | - | ||||||
| 125 | Q_CHECK_PTR(_blocks); never executed: qt_check_pointer(__FILE__,125);
| 0-2425869 | ||||||
| 126 | - | |||||||
| 127 | for (int index = _blockCount; index < _allocatedBlocks; ++index)
| 2425652-19416801 | ||||||
| 128 | _blocks[index] = nullptr; executed 19417183 times by 148 tests: _blocks[index] = nullptr;Executed by:
| 19417183 | ||||||
| 129 | } executed 2425679 times by 148 tests: end of blockExecuted by:
| 2425679 | ||||||
| 130 | - | |||||||
| 131 | char *&block = _blocks[_blockCount]; | - | ||||||
| 132 | - | |||||||
| 133 | if (! block) {
| 0-2751604 | ||||||
| 134 | block = (char *) malloc(BLOCK_SIZE); | - | ||||||
| 135 | Q_CHECK_PTR(block); never executed: qt_check_pointer(__FILE__,135);
| 0-2753243 | ||||||
| 136 | } executed 2753231 times by 148 tests: end of blockExecuted by:
| 2753231 | ||||||
| 137 | - | |||||||
| 138 | _ptr = block; | - | ||||||
| 139 | _end = _ptr + BLOCK_SIZE; | - | ||||||
| 140 | - | |||||||
| 141 | void *addr = _ptr; | - | ||||||
| 142 | _ptr += size; | - | ||||||
| 143 | return addr; executed 2753238 times by 148 tests: return addr;Executed by:
| 2753238 | ||||||
| 144 | } | - | ||||||
| 145 | - | |||||||
| 146 | private: | - | ||||||
| 147 | char **_blocks = nullptr; | - | ||||||
| 148 | int _allocatedBlocks = 0; | - | ||||||
| 149 | int _blockCount = -1; | - | ||||||
| 150 | char *_ptr = nullptr; | - | ||||||
| 151 | char *_end = nullptr; | - | ||||||
| 152 | QVector<QString*> strings; | - | ||||||
| 153 | - | |||||||
| 154 | enum | - | ||||||
| 155 | { | - | ||||||
| 156 | BLOCK_SIZE = 8 * 1024, | - | ||||||
| 157 | DEFAULT_BLOCK_COUNT = 8 | - | ||||||
| 158 | }; | - | ||||||
| 159 | }; | - | ||||||
| 160 | - | |||||||
| 161 | class QML_PARSER_EXPORT Managed | - | ||||||
| 162 | { | - | ||||||
| 163 | Q_DISABLE_COPY(Managed) | - | ||||||
| 164 | public: | - | ||||||
| 165 | Managed() = default; | - | ||||||
| 166 | ~Managed() = default; | - | ||||||
| 167 | - | |||||||
| 168 | void *operator new(size_t size, MemoryPool *pool) { return pool->allocate(size); } executed 71782270 times by 148 tests: return pool->allocate(size);Executed by:
| 71782270 | ||||||
| 169 | void operator delete(void *) {} | - | ||||||
| 170 | void operator delete(void *, MemoryPool *) {} | - | ||||||
| 171 | }; | - | ||||||
| 172 | - | |||||||
| 173 | } // namespace QQmlJS | - | ||||||
| 174 | - | |||||||
| 175 | QT_QML_END_NAMESPACE | - | ||||||
| 176 | - | |||||||
| 177 | #endif | - | ||||||
| Source code | Switch to Preprocessed file |