D29138: [Solid] Replace foreach (deprecated) with range/index for

Méven Car noreply at phabricator.kde.org
Fri Apr 24 06:43:56 BST 2020


meven added a comment.


  In D29138#656094 <https://phabricator.kde.org/D29138#656094>, @dfaure wrote:
  
  > Wow those iterations over map.keys() were awful.
  
  
  We still have a few of those in solid :
  
    $ rg ".keys\(\)"
    src/tools/solid-hardware/solid-hardware.cpp
    151:    Q_FOREACH (const QString &key, properties.keys())
    
    src/solid/devices/backends/udisks2/udisksdevicebackend.cpp
    220:    Q_FOREACH (const QString &iface, interfaces_and_properties.keys()) {
    
    src/solid/devices/backends/fstab/fstabhandling.cpp
    219:    QStringList devices = globalFstabCache->localData().m_mtabCache.keys();
    
    src/solid/devices/backends/udisks2/udisksmanager.cpp
    179:    qCDebug(UDISKS2) << udi << "has new interfaces:" << interfaces_and_properties.keys();
    201:    else if (m_deviceCache.contains(udi) && interfaces_and_properties.keys().contains(UD2_DBUS_INTERFACE_FILESYSTEM)) {
    
    src/solid/devices/backends/iokit/iokitstorageaccess.cpp
    89:    Q_FOREACH (const QString &property, changes.keys()) {
    
    src/solid/devices/backends/iokit/iokitopticaldrive.cpp
    284:    foreach (const Solid::OpticalDrive::MediumType type, d->cdTypeMap.keys()) {
    289:    foreach (const Solid::OpticalDrive::MediumType type, d->dvdTypeMap.keys()) {
    294:    foreach (const Solid::OpticalDrive::MediumType type, d->bdTypeMap.keys()) {
    
    src/solid/devices/backends/hal/halopticaldisc.cpp
    34:    Q_FOREACH (const Solid::OpticalDisc::ContentType type, map.keys()) {
    
    src/solid/devices/backends/fakehw/fakeopticaldisc.cpp
    38:    Q_FOREACH (const Solid::OpticalDisc::ContentType type, map.keys()) {
    
    src/solid/devices/backends/fakehw/fakestorageaccess.cpp
    60:    Q_FOREACH (const QString &property, changes.keys()) {
    
    src/solid/devices/backends/hal/halcdrom.cpp
    55:    Q_FOREACH (const Solid::OpticalDrive::MediumType type, map.keys()) {
    
    src/solid/devices/backends/fakehw/fakecdrom.cpp
    48:    Q_FOREACH (const Solid::OpticalDrive::MediumType type, map.keys()) {
    
    src/solid/devices/backends/udisks2/udisksopticaldrive.cpp
    63:        Q_FOREACH (const QDBusObjectPath &objPath, reply.value().keys()) {
    208:    Q_FOREACH (const Solid::OpticalDrive::MediumType &type, map.keys()) {

INLINE COMMENTS

> fakemanager.cpp:135
>      QStringList result;
> -    FakeDevice *device;
> -    Q_FOREACH (device, d->loadedDevices) {
> +    for (FakeDevice *device : qAsConst(d->loadedDevices)) {
>          if (device->property(key).toString() == value) {

I guess you can const the FakeDevice

> fakemanager.cpp:147
>      QStringList result;
> -    FakeDevice *device;
> -    Q_FOREACH (device, d->loadedDevices) {
> +    for (FakeDevice *device : qAsConst(d->loadedDevices)) {
>          if (device->queryDeviceInterface(type)) {

I guess you can const the FakeDevice

REPOSITORY
  R245 Solid

BRANCH
  l-foreach (branched from master)

REVISION DETAIL
  https://phabricator.kde.org/D29138

To: ahmadsamir, #frameworks, dfaure, apol, meven
Cc: bruns, kde-frameworks-devel, LeGast00n, cblack, michaelh, ngraham
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20200424/090c2855/attachment.html>


More information about the Kde-frameworks-devel mailing list