fix(device): remove redundant loop in network device generation#701
Conversation
Remove the outer loop iterating lstDevice in generatorNetworkDevice, as inner operations do not depend on the loop variable, fixing incorrect network device filtering. 移除generatorNetworkDevice中遍历lstDevice的多余外层循环,内层操作 不依赖循环变量,修复网络设备过滤异常的问题。 Log: 修复网络设备生成中循环冗余导致的过滤异常 PMS: BUG-369057 Influence: 修复后网络设备列表生成逻辑正确,避免无线网卡等设备被错误过滤。
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors network device generation to remove a redundant outer loop over lstDevice and perform network-device filtering and creation once per lshw entry, fixing incorrect filtering of devices like WLAN adapters. Flow diagram for updated network device generation logicflowchart TD
A[generatorNetworkDevice iterate lshw entries] --> B[Read logicalNameLshw and macAddressLshw]
B --> C{isValidLogicalName}
C -->|no| A
C -->|yes| D{isValidMAC}
D -->|no| A
D -->|yes| E{logicalNameLshw contains wlan and hasWlan}
E -->|yes| A
E -->|no| F[Create DeviceNetwork instance]
F --> G[device.setInfoFromLshw]
G --> H[Append device to lstDevice]
H --> I{logicalNameLshw contains wlan}
I -->|yes| J[set hasWlan true]
I -->|no| A
J --> A
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 建议使用智能指针管理 DeviceNetwork 对象的生命周期,避免潜在的手动 delete 遗漏导致内存泄漏
void DeviceGenerator::generatorNetworkDevice()
{
// ... 前置代码 ...
for (auto it = lstLshw.begin(); it != lstLshw.end(); ++it) {
const QString &logicalNameLshw = (*it)["logical name"];
const QString &macAddressLshw = (*it)["serial"];
if (!isValidLogicalName(logicalNameLshw))
continue;
if (!isValidMAC(macAddressLshw))
continue;
if (logicalNameLshw.contains("wlan", Qt::CaseInsensitive) && hasWlan) //common sense: one PC only have 1 wlan device
continue;
// 使用 std::unique_ptr 或 QScopedPointer 进行安全管理
std::unique_ptr<DeviceNetwork> device(new DeviceNetwork());
device->setInfoFromLshw(*it);
lstDevice.append(device.release()); // 释放所有权给 lstDevice
if (logicalNameLshw.contains("wlan", Qt::CaseInsensitive))
hasWlan = true;
}
// ... 后置代码 ...
} |
|
/merge |
Remove the outer loop iterating lstDevice in generatorNetworkDevice, as inner operations do not depend on the loop variable, fixing incorrect network device filtering.
移除generatorNetworkDevice中遍历lstDevice的多余外层循环,内层操作
不依赖循环变量,修复网络设备过滤异常的问题。
Log: 修复网络设备生成中循环冗余导致的过滤异常
PMS: BUG-369057
Influence: 修复后网络设备列表生成逻辑正确,避免无线网卡等设备被错误过滤。
Summary by Sourcery
Bug Fixes: