Skip to content

Commit

Permalink
Merge pull request #18 from Integral-Tech/range-based-for
Browse files Browse the repository at this point in the history
refactor: use range-based for loop to enhance readability
  • Loading branch information
Inokinoki authored Nov 9, 2024
2 parents 303cdfb + e3d9f91 commit d4d79b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(QEFIVAR_LIB)
Expand Down
9 changes: 4 additions & 5 deletions qefi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ QByteArray qefi_get_variable(QUuid uuid, QString name)
}
else
{
for (size_t i = 0; i < length; i++) {
value.append(buffer[i]);
for (const auto &byte : buffer) {
value.append(byte);
}
}

Expand Down Expand Up @@ -1269,9 +1269,8 @@ QByteArray QEFILoadOption::format()
// Append name
loadOptionData.append(name);
// Append DP
for (QList<QSharedPointer<QEFIDevicePath> >::iterator i = m_devicePathList.begin();
i != m_devicePathList.end(); i++) {
loadOptionData.append(qefi_format_dp((*i).get()));
for (const auto &dp : std::as_const(m_devicePathList)) {
loadOptionData.append(qefi_format_dp(dp.get()));
}
// Append the end of DP
loadOptionData.append((char)QEFIDevicePathType::DP_End);
Expand Down
7 changes: 3 additions & 4 deletions qefidpacpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ QByteArray qefi_format_dp_acpi_adr(QEFIDevicePath *dp)
buffer.append((char)4);
buffer.append((char)0);
// Append the fields
QList<quint32> addresses = dp_instance->addresses();
for (int i = 0; i < addresses.size(); i++) {
quint32 adr =
qToLittleEndian<quint32>(addresses[i]);
const auto &addresses = dp_instance->addresses();
for (const auto &addr : addresses) {
quint32 adr = qToLittleEndian<quint32>(addr);
buffer.append((const char *)&adr, sizeof(quint32));
}

Expand Down
13 changes: 6 additions & 7 deletions tests/test_load_option_parsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ void TestLoadOptionParsing::testParseTestBootData()
QVERIFY(loadOption.name() == QString(test_boot_name));
QVERIFY(loadOption.path() == QString(test_boot_path));
QVERIFY(loadOption.devicePathList().size() == 2);
auto devicePathList = loadOption.devicePathList();
for (int i = 0; i < devicePathList.size(); i++) {
QSharedPointer<QEFIDevicePath> &dp = devicePathList[i];

const auto &devicePathList = loadOption.devicePathList();
for (const auto &dp : devicePathList) {
if (dp->type() == QEFIDevicePathType::DP_Media &&
dp->subType() == QEFIDevicePathMediaSubType::MEDIA_HD) {
QEFIDevicePathMediaHD *dpMediaHD =
Expand All @@ -46,9 +46,8 @@ void TestLoadOptionParsing::testParseTestBootData2()
QVERIFY(loadOption.name() == QString(test_boot_name2));
QVERIFY(loadOption.path() == QString(test_boot_path2));
QVERIFY(loadOption.devicePathList().size() == 2);
auto devicePathList = loadOption.devicePathList();
for (int i = 0; i < devicePathList.size(); i++) {
QSharedPointer<QEFIDevicePath> &dp = devicePathList[i];
const auto &devicePathList = loadOption.devicePathList();
for (const auto &dp : devicePathList) {
if (dp->type() == QEFIDevicePathType::DP_Media &&
dp->subType() == QEFIDevicePathMediaSubType::MEDIA_HD) {
QEFIDevicePathMediaHD *dpMediaHD =
Expand All @@ -75,4 +74,4 @@ void TestLoadOptionParsing::testParseEmptyData()

QTEST_MAIN(TestLoadOptionParsing)

#include "test_load_option_parsing.moc"
#include "test_load_option_parsing.moc"

0 comments on commit d4d79b4

Please sign in to comment.