summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-04-11 11:18:52 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-04-11 19:44:41 +0000
commitb3713b3ba84f1cccd998c49248e9b8f030b9587a (patch)
treeacdac020995f6381f2daef3314e1be4f00716a50 /src
parent56a1b19b0cce97374fcd21c165e23d2cd80a6417 (diff)
Port indexed for-loops from int to qsizetype
... and port (already or soon-expected-to-be) count() to size(). These changes are considered trivial, in that nothing but the loop variable needs adjustment. The alternative, a port to ranged for-loops, I dismissed for these loops, either because the loop index was used for something else (first/last check, zip iteration) or I was just too lazy to prove that the container under iteration isn't changed. In some cases, I may have forgotten to port to ranged loops, even though it would be trivially safe. This was already much more complex than anticipated :) Also fix post-increment to pre-increment. It doesn't matter for integral types, but developers that regularly read and write post-increment for integral types will likely fail to switch to pre-increment for iterators types, where the difference does matter, so increase the exposure of code readers to the idiomatic form. Pick-to: 6.3 Task-number: QTBUG-102463 Change-Id: Ia6f2960dc52d46ffbd48f12446e9b0f7c70df162 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/darwin/btservicerecord.mm2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp4
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_darwin.mm2
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_android.cpp2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp2
-rw-r--r--src/bluetooth/qbluetoothserviceinfo.cpp2
-rw-r--r--src/bluetooth/qlowenergycontrollerbase.cpp2
-rw-r--r--src/nfc/qndefmessage.cpp4
-rw-r--r--src/tools/sdpscanner/main.cpp2
10 files changed, 12 insertions, 12 deletions
diff --git a/src/bluetooth/darwin/btservicerecord.mm b/src/bluetooth/darwin/btservicerecord.mm
index 3bd6979f..c7e8fecc 100644
--- a/src/bluetooth/darwin/btservicerecord.mm
+++ b/src/bluetooth/darwin/btservicerecord.mm
@@ -79,7 +79,7 @@ QBluetoothUuid profile_uuid(const QBluetoothServiceInfo &serviceInfo)
if (var.isValid()) {
const Sequence seq(var.value<Sequence>());
- for (int i = 0; i < seq.count(); ++i) {
+ for (qsizetype i = 0; i < seq.size(); ++i) {
QBluetoothUuid uuid(seq.at(i).value<QBluetoothUuid>());
if (uuid.isNull())
continue;
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index ce94fc9b..47ca5910 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -339,7 +339,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevices(
// the advertisement package.
// If address is same but name different then we keep both entries.
- for (int i = 0; i < discoveredDevices.size(); i++) {
+ for (qsizetype i = 0; i < discoveredDevices.size(); ++i) {
if (discoveredDevices[i].address() == info.address()) {
QBluetoothDeviceInfo::Fields updatedFields = QBluetoothDeviceInfo::Field::None;
if (discoveredDevices[i].rssi() != info.rssi()) {
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index c4787779..3945e918 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -318,7 +318,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(const QString &devicePat
// Cache the properties so we do not have to access dbus every time to get a value
devicesProperties[devicePath] = properties;
- for (int i = 0; i < discoveredDevices.size(); i++) {
+ for (qsizetype i = 0; i < discoveredDevices.size(); ++i) {
if (discoveredDevices[i].address() == deviceInfo.address()) {
if (lowEnergySearchTimeout > 0 && discoveredDevices[i] == deviceInfo) {
qCDebug(QT_BT_BLUEZ) << "Duplicate: " << deviceInfo.address();
@@ -436,7 +436,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(const QString &
if (changed_properties.contains(QStringLiteral("RSSI"))
|| changed_properties.contains(QStringLiteral("ManufacturerData"))) {
- for (int i = 0; i < discoveredDevices.size(); i++) {
+ for (qsizetype i = 0; i < discoveredDevices.size(); ++i) {
if (discoveredDevices[i].address() == info.address()) {
QBluetoothDeviceInfo::Fields updatedFields = QBluetoothDeviceInfo::Field::None;
if (changed_properties.contains(QStringLiteral("RSSI"))) {
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_darwin.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_darwin.mm
index 7fac8264..67ef290a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_darwin.mm
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_darwin.mm
@@ -503,7 +503,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(const QBluetoothDeviceIn
#else
true;
#endif // Q_OS_MACOS
- for (int i = 0, e = discoveredDevices.size(); i < e; ++i) {
+ for (qsizetype i = 0, e = discoveredDevices.size(); i < e; ++i) {
if (isLE) {
if (discoveredDevices[i].deviceUuid() == newDeviceInfo.deviceUuid()) {
QBluetoothDeviceInfo::Fields updatedFields = QBluetoothDeviceInfo::Field::None;
diff --git a/src/bluetooth/qbluetoothlocaldevice_android.cpp b/src/bluetooth/qbluetoothlocaldevice_android.cpp
index 0c33d59f..84fb6467 100644
--- a/src/bluetooth/qbluetoothlocaldevice_android.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_android.cpp
@@ -148,7 +148,7 @@ void QBluetoothLocalDevicePrivate::processHostModeChange(QBluetoothLocalDevice::
// Otherwise it returns the index of address in pendingPairings
int QBluetoothLocalDevicePrivate::pendingPairing(const QBluetoothAddress &address)
{
- for (int i = 0; i < pendingPairings.count(); i++) {
+ for (qsizetype i = 0; i < pendingPairings.size(); ++i) {
if (pendingPairings.at(i).first == address)
return i;
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index ce1d5729..f3120c1c 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -383,7 +383,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons
qCDebug(QT_BT_BLUEZ) << "Minimal uuid list for" << deviceAddress.toString() << uuidStrings;
QBluetoothUuid uuid;
- for (int i = 0; i < uuidStrings.count(); i++) {
+ for (qsizetype i = 0; i < uuidStrings.size(); ++i) {
uuid = QBluetoothUuid(uuidStrings.at(i));
if (uuid.isNull())
continue;
diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp
index ebc7e83e..f7a842b3 100644
--- a/src/bluetooth/qbluetoothserviceinfo.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo.cpp
@@ -541,7 +541,7 @@ QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const
return results;
const QBluetoothServiceInfo::Sequence seq = var.value<QBluetoothServiceInfo::Sequence>();
- for (int i = 0; i < seq.count(); i++)
+ for (qsizetype i = 0; i < seq.size(); ++i)
results.append(seq.at(i).value<QBluetoothUuid>());
return results;
diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp
index c69bbb2a..ada5a3e6 100644
--- a/src/bluetooth/qlowenergycontrollerbase.cpp
+++ b/src/bluetooth/qlowenergycontrollerbase.cpp
@@ -172,7 +172,7 @@ QLowEnergyCharacteristic QLowEnergyControllerPrivate::characteristicForHandle(
// check whether it is the handle of the characteristic value or its descriptors
QList<QLowEnergyHandle> charHandles = service->characteristicList.keys();
std::sort(charHandles.begin(), charHandles.end());
- for (int i = charHandles.size() - 1; i >= 0; i--) {
+ for (qsizetype i = charHandles.size() - 1; i >= 0; --i) {
if (charHandles.at(i) > handle)
continue;
diff --git a/src/nfc/qndefmessage.cpp b/src/nfc/qndefmessage.cpp
index 12cf681c..94141616 100644
--- a/src/nfc/qndefmessage.cpp
+++ b/src/nfc/qndefmessage.cpp
@@ -287,7 +287,7 @@ bool QNdefMessage::operator==(const QNdefMessage &other) const
if (size() != other.size())
return false;
- for (int i = 0; i < count(); ++i) {
+ for (qsizetype i = 0; i < size(); ++i) {
if (at(i) != other.at(i))
return false;
}
@@ -309,7 +309,7 @@ QByteArray QNdefMessage::toByteArray() const
QByteArray m;
- for (int i = 0; i < count(); ++i) {
+ for (qsizetype i = 0; i < size(); ++i) {
const QNdefRecord &record = at(i);
quint8 flags = record.typeNameFormat();
diff --git a/src/tools/sdpscanner/main.cpp b/src/tools/sdpscanner/main.cpp
index 038f4062..210f1809 100644
--- a/src/tools/sdpscanner/main.cpp
+++ b/src/tools/sdpscanner/main.cpp
@@ -153,7 +153,7 @@ static void parseAttributeValues(sdp_data_t *data, int indentation, QByteArray &
QByteArray text = QByteArray::fromRawData(data->val.str, data->unitSize);
bool hasNonPrintableChar = false;
- for (int i = 0; i < text.count(); i++) {
+ for (qsizetype i = 0; i < text.size(); ++i) {
if (text[i] == '\0') {
text.resize(i); // cut trailing content
break;