solid: do not copy lists

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-11-11 04:50:31 +02:00
parent 8ee64ca77c
commit 85758c0a6d
2 changed files with 34 additions and 38 deletions

View file

@ -176,8 +176,7 @@ QSet<Solid::DeviceInterface::Type> UDevManager::supportedInterfaces() const
QStringList UDevManager::allDevices()
{
QStringList res;
const UdevQt::DeviceList deviceList = d->m_client->allDevices();
foreach (const UdevQt::Device &device, deviceList) {
foreach (const UdevQt::Device &device, d->m_client->allDevices()) {
if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
res << udiPrefix() + device.sysfsPath();
}

View file

@ -39,8 +39,7 @@ Solid::DeviceManagerPrivate::DeviceManagerPrivate()
{
loadBackends();
QList<QObject*> backends = managerBackends();
foreach (QObject *backend, backends) {
foreach (QObject *backend, managerBackends()) {
connect(backend, SIGNAL(deviceAdded(QString)),
this, SLOT(_k_deviceAdded(QString)));
connect(backend, SIGNAL(deviceRemoved(QString)),
@ -52,8 +51,7 @@ Solid::DeviceManagerPrivate::DeviceManagerPrivate()
Solid::DeviceManagerPrivate::~DeviceManagerPrivate()
{
QList<QObject*> backends = managerBackends();
foreach (QObject *backend, backends) {
foreach (QObject *backend, managerBackends()) {
disconnect(backend, 0, this, 0);
}
@ -69,16 +67,15 @@ Solid::DeviceManagerPrivate::~DeviceManagerPrivate()
QList<Solid::Device> Solid::Device::allDevices()
{
QList<Device> list;
QList<QObject*> backends = globalDeviceStorage()->managerBackends();
foreach (QObject *backendObj, backends) {
foreach (QObject *backendObj, globalDeviceStorage()->managerBackends()) {
Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
if (backend == 0) continue;
if (backend == 0) {
continue;
}
QStringList udis = backend->allDevices();
foreach (const QString &udi, udis) {
foreach (const QString &udi, backend->allDevices()) {
list.append(Device(udi));
}
}
@ -105,17 +102,18 @@ QList<Solid::Device> Solid::Device::listFromType(const DeviceInterface::Type &ty
const QString &parentUdi)
{
QList<Device> list;
QList<QObject*> backends = globalDeviceStorage()->managerBackends();
foreach (QObject *backendObj, backends) {
foreach (QObject *backendObj, globalDeviceStorage()->managerBackends()) {
Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
if (backend == 0) continue;
if (!backend->supportedInterfaces().contains(type)) continue;
if (backend == 0) {
continue;
}
if (!backend->supportedInterfaces().contains(type)) {
continue;
}
QStringList udis = backend->devicesFromQuery(parentUdi, type);
foreach (const QString &udi, udis) {
foreach (const QString &udi, backend->devicesFromQuery(parentUdi, type)) {
list.append(Device(udi));
}
}
@ -127,13 +125,14 @@ QList<Solid::Device> Solid::Device::listFromQuery(const Predicate &predicate,
const QString &parentUdi)
{
QList<Device> list;
QList<QObject*> backends = globalDeviceStorage()->managerBackends();
QSet<DeviceInterface::Type> usedTypes = predicate.usedTypes();
foreach (QObject *backendObj, backends) {
foreach (QObject *backendObj, globalDeviceStorage()->managerBackends()) {
Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
if (backend == 0) continue;
if (backend == 0) {
continue;
}
QSet<QString> udis;
if (predicate.isValid()) {
@ -149,8 +148,7 @@ QList<Solid::Device> Solid::Device::listFromQuery(const Predicate &predicate,
udis += QSet<QString>::fromList(backend->allDevices());
}
foreach (const QString &udi, udis)
{
foreach (const QString &udi, udis) {
Device dev(udi);
bool matches = false;
@ -161,8 +159,7 @@ QList<Solid::Device> Solid::Device::listFromQuery(const Predicate &predicate,
matches = predicate.matches(dev);
}
if (matches)
{
if (matches) {
list.append(dev);
}
}
@ -250,18 +247,18 @@ Solid::DevicePrivate *Solid::DeviceManagerPrivate::findRegisteredDevice(const QS
Solid::Ifaces::Device *Solid::DeviceManagerPrivate::createBackendObject(const QString &udi)
{
QList<QObject*> backends = globalDeviceStorage()->managerBackends();
foreach (QObject *backendObj, backends) {
foreach (QObject *backendObj, globalDeviceStorage()->managerBackends()) {
Ifaces::DeviceManager *backend = qobject_cast<Ifaces::DeviceManager *>(backendObj);
if (backend == 0) continue;
if (!udi.startsWith(backend->udiPrefix())) continue;
Ifaces::Device *iface = 0;
if (backend == 0) {
continue;
}
if (!udi.startsWith(backend->udiPrefix())) {
continue;
}
QObject *object = backend->createDevice(udi);
iface = qobject_cast<Ifaces::Device *>(object);
Ifaces::Device *iface = qobject_cast<Ifaces::Device *>(object);
if (iface == 0) {
delete object;