Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use range-based for loop to enhance readability #18

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading