Skip to content

Commit 783c3b4

Browse files
committed
refactor: use range-based for loop to enhance readability
1 parent 303cdfb commit 783c3b4

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

qefi.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ QByteArray qefi_get_variable(QUuid uuid, QString name)
633633
}
634634
else
635635
{
636-
for (size_t i = 0; i < length; i++) {
637-
value.append(buffer[i]);
636+
for (const auto &byte : buffer) {
637+
value.append(byte);
638638
}
639639
}
640640

@@ -1269,9 +1269,8 @@ QByteArray QEFILoadOption::format()
12691269
// Append name
12701270
loadOptionData.append(name);
12711271
// Append DP
1272-
for (QList<QSharedPointer<QEFIDevicePath> >::iterator i = m_devicePathList.begin();
1273-
i != m_devicePathList.end(); i++) {
1274-
loadOptionData.append(qefi_format_dp((*i).get()));
1272+
for (const auto &dp : std::as_const(m_devicePathList)) {
1273+
loadOptionData.append(qefi_format_dp(dp.get()));
12751274
}
12761275
// Append the end of DP
12771276
loadOptionData.append((char)QEFIDevicePathType::DP_End);

qefidpacpi.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ QByteArray qefi_format_dp_acpi_adr(QEFIDevicePath *dp)
199199
buffer.append((char)4);
200200
buffer.append((char)0);
201201
// Append the fields
202-
QList<quint32> addresses = dp_instance->addresses();
203-
for (int i = 0; i < addresses.size(); i++) {
204-
quint32 adr =
205-
qToLittleEndian<quint32>(addresses[i]);
202+
const auto &addresses = dp_instance->addresses();
203+
for (const auto &addr : addresses) {
204+
quint32 adr = qToLittleEndian<quint32>(addr);
206205
buffer.append((const char *)&adr, sizeof(quint32));
207206
}
208207

tests/test_load_option_parsing.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ void TestLoadOptionParsing::testParseTestBootData()
2020
QVERIFY(loadOption.name() == QString(test_boot_name));
2121
QVERIFY(loadOption.path() == QString(test_boot_path));
2222
QVERIFY(loadOption.devicePathList().size() == 2);
23-
auto devicePathList = loadOption.devicePathList();
24-
for (int i = 0; i < devicePathList.size(); i++) {
25-
QSharedPointer<QEFIDevicePath> &dp = devicePathList[i];
23+
24+
const auto &devicePathList = loadOption.devicePathList();
25+
for (const auto &dp : devicePathList) {
2626
if (dp->type() == QEFIDevicePathType::DP_Media &&
2727
dp->subType() == QEFIDevicePathMediaSubType::MEDIA_HD) {
2828
QEFIDevicePathMediaHD *dpMediaHD =
@@ -46,9 +46,8 @@ void TestLoadOptionParsing::testParseTestBootData2()
4646
QVERIFY(loadOption.name() == QString(test_boot_name2));
4747
QVERIFY(loadOption.path() == QString(test_boot_path2));
4848
QVERIFY(loadOption.devicePathList().size() == 2);
49-
auto devicePathList = loadOption.devicePathList();
50-
for (int i = 0; i < devicePathList.size(); i++) {
51-
QSharedPointer<QEFIDevicePath> &dp = devicePathList[i];
49+
const auto &devicePathList = loadOption.devicePathList();
50+
for (const auto &dp : devicePathList) {
5251
if (dp->type() == QEFIDevicePathType::DP_Media &&
5352
dp->subType() == QEFIDevicePathMediaSubType::MEDIA_HD) {
5453
QEFIDevicePathMediaHD *dpMediaHD =
@@ -75,4 +74,4 @@ void TestLoadOptionParsing::testParseEmptyData()
7574

7675
QTEST_MAIN(TestLoadOptionParsing)
7776

78-
#include "test_load_option_parsing.moc"
77+
#include "test_load_option_parsing.moc"

0 commit comments

Comments
 (0)