| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include <QtCore/qarraydata.h> | - |
| 43 | #include <QtCore/private/qtools_p.h> | - |
| 44 | | - |
| 45 | #include <stdlib.h> | - |
| 46 | | - |
| 47 | QT_BEGIN_NAMESPACE | - |
| 48 | | - |
| 49 | #if defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL) | - |
| 50 | #pragma GCC diagnostic push | - |
| 51 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" | - |
| 52 | #endif | - |
| 53 | | - |
| 54 | const QArrayData QArrayData::shared_null[2] = { | - |
| 55 | { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, sizeof(QArrayData) }, // shared null | - |
| 56 | /* zero initialized terminator */}; | - |
| 57 | | - |
| 58 | static const QArrayData qt_array[3] = { | - |
| 59 | { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, sizeof(QArrayData) }, // shared empty | - |
| 60 | { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, sizeof(QArrayData) }, // unsharable empty | - |
| 61 | /* zero initialized terminator */}; | - |
| 62 | | - |
| 63 | #if defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && !defined(Q_CC_INTEL) | - |
| 64 | #pragma GCC diagnostic pop | - |
| 65 | #endif | - |
| 66 | | - |
| 67 | static const QArrayData &qt_array_empty = qt_array[0]; | - |
| 68 | static const QArrayData &qt_array_unsharable_empty = qt_array[1]; | - |
| 69 | | - |
| 70 | QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, | - |
| 71 | size_t capacity, AllocationOptions options) | - |
| 72 | { | - |
| 73 | // Alignment is a power of two | - |
| 74 | Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData) executed (the execution status of this line is deduced): qt_noop(); | - |
| 75 | && !(alignment & (alignment - 1))); | - |
| 76 | | - |
| 77 | // Don't allocate empty headers | - |
| 78 | if (!(options & RawData) && !capacity) evaluated: !(options & RawData)| yes Evaluation Count:146977606 | yes Evaluation Count:1924613 |
evaluated: !capacity| yes Evaluation Count:4421489 | yes Evaluation Count:142555472 |
| 1924613-146977606 |
| 79 | return !(options & Unsharable) executed: return !(options & Unsharable) ? const_cast<QArrayData *>(&qt_array_empty) : const_cast<QArrayData *>(&qt_array_unsharable_empty);Execution Count:4421484 | 4421484 |
| 80 | ? const_cast<QArrayData *>(&qt_array_empty) executed: return !(options & Unsharable) ? const_cast<QArrayData *>(&qt_array_empty) : const_cast<QArrayData *>(&qt_array_unsharable_empty);Execution Count:4421484 | 4421484 |
| 81 | : const_cast<QArrayData *>(&qt_array_unsharable_empty); executed: return !(options & Unsharable) ? const_cast<QArrayData *>(&qt_array_empty) : const_cast<QArrayData *>(&qt_array_unsharable_empty);Execution Count:4421484 | 4421484 |
| 82 | | - |
| 83 | size_t headerSize = sizeof(QArrayData); executed (the execution status of this line is deduced): size_t headerSize = sizeof(QArrayData); | - |
| 84 | | - |
| 85 | // Allocate extra (alignment - Q_ALIGNOF(QArrayData)) padding bytes so we | - |
| 86 | // can properly align the data array. This assumes malloc is able to | - |
| 87 | // provide appropriate alignment for the header -- as it should! | - |
| 88 | // Padding is skipped when allocating a header for RawData. | - |
| 89 | if (!(options & RawData)) evaluated: !(options & RawData)| yes Evaluation Count:142556160 | yes Evaluation Count:1924622 |
| 1924622-142556160 |
| 90 | headerSize += (alignment - Q_ALIGNOF(QArrayData)); executed: headerSize += (alignment - __alignof__(QArrayData));Execution Count:142556289 | 142556289 |
| 91 | | - |
| 92 | // Allocate additional space if array is growing | - |
| 93 | if (options & Grow) evaluated: options & Grow| yes Evaluation Count:11793134 | yes Evaluation Count:132688185 |
| 11793134-132688185 |
| 94 | capacity = qAllocMore(objectSize * capacity, headerSize) / int(objectSize); executed: capacity = qAllocMore(objectSize * capacity, headerSize) / int(objectSize);Execution Count:11793118 | 11793118 |
| 95 | | - |
| 96 | size_t allocSize = headerSize + objectSize * capacity; executed (the execution status of this line is deduced): size_t allocSize = headerSize + objectSize * capacity; | - |
| 97 | | - |
| 98 | QArrayData *header = static_cast<QArrayData *>(::malloc(allocSize)); executed (the execution status of this line is deduced): QArrayData *header = static_cast<QArrayData *>(::malloc(allocSize)); | - |
| 99 | if (header) { partially evaluated: header| yes Evaluation Count:144481966 | no Evaluation Count:0 |
| 0-144481966 |
| 100 | quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1) executed (the execution status of this line is deduced): quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1) | - |
| 101 | & ~(alignment - 1); executed (the execution status of this line is deduced): & ~(alignment - 1); | - |
| 102 | | - |
| 103 | header->ref.atomic.store(bool(!(options & Unsharable))); executed (the execution status of this line is deduced): header->ref.atomic.store(bool(!(options & Unsharable))); | - |
| 104 | header->size = 0; executed (the execution status of this line is deduced): header->size = 0; | - |
| 105 | header->alloc = capacity; executed (the execution status of this line is deduced): header->alloc = capacity; | - |
| 106 | header->capacityReserved = bool(options & CapacityReserved); executed (the execution status of this line is deduced): header->capacityReserved = bool(options & CapacityReserved); | - |
| 107 | header->offset = data - quintptr(header); executed (the execution status of this line is deduced): header->offset = data - quintptr(header); | - |
| 108 | } executed: }Execution Count:144478879 | 144478879 |
| 109 | | - |
| 110 | return header; executed: return header;Execution Count:144478960 | 144478960 |
| 111 | } | - |
| 112 | | - |
| 113 | void QArrayData::deallocate(QArrayData *data, size_t objectSize, | - |
| 114 | size_t alignment) | - |
| 115 | { | - |
| 116 | // Alignment is a power of two | - |
| 117 | Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData) executed (the execution status of this line is deduced): qt_noop(); | - |
| 118 | && !(alignment & (alignment - 1))); | - |
| 119 | Q_UNUSED(objectSize) Q_UNUSED(alignment) executed (the execution status of this line is deduced): (void)objectSize; (void)alignment; | - |
| 120 | | - |
| 121 | if (data == &qt_array_unsharable_empty) evaluated: data == &qt_array_unsharable_empty| yes Evaluation Count:3528968 | yes Evaluation Count:144517736 |
| 3528968-144517736 |
| 122 | return; executed: return;Execution Count:3528970 | 3528970 |
| 123 | | - |
| 124 | Q_ASSERT_X(!data->ref.isStatic(), "QArrayData::deallocate", "Static data can not be deleted"); executed (the execution status of this line is deduced): qt_noop(); | - |
| 125 | ::free(data); executed (the execution status of this line is deduced): ::free(data); | - |
| 126 | } executed: }Execution Count:144517383 | 144517383 |
| 127 | | - |
| 128 | QT_END_NAMESPACE | - |
| 129 | | - |
| | |