From 6d0965ef3f344d028d8118fd557f8905894dcea2 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 9 Sep 2016 11:25:04 +0200 Subject: [PATCH] Keep an immutable copy for every scanned Device* to avoid rescans. --- .../partition/core/PartitionCoreModule.cpp | 26 +++++++++++-------- .../partition/core/PartitionCoreModule.h | 7 ++--- src/modules/partition/gui/ChoicePage.cpp | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 4e8da4f56..bba2fedc5 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -97,6 +97,7 @@ isIso9660( const Device* device ) PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device ) : device( _device ) , partitionModel( new PartitionModel ) + , immutableDevice( new Device( *_device ) ) {} PartitionCoreModule::DeviceInfo::~DeviceInfo() @@ -235,7 +236,7 @@ PartitionCoreModule::bootLoaderModel() const } PartitionModel* -PartitionCoreModule::partitionModelForDevice( Device* device ) const +PartitionCoreModule::partitionModelForDevice( const Device* device ) const { DeviceInfo* info = infoForDevice( device ); Q_ASSERT( info ); @@ -244,14 +245,14 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const Device* -PartitionCoreModule::createImmutableDeviceCopy( Device* device ) +PartitionCoreModule::immutableDeviceCopy( const Device* device ) { - CoreBackend* backend = CoreBackendManager::self()->backend(); + Q_ASSERT( device ); + DeviceInfo* info = infoForDevice( device ); + if ( !info ) + return nullptr; - QString node = device->deviceNode(); - cDebug() << "Creating immutable copy for node:" << node; - Device* deviceBefore = backend->scanDevice( node ); - return deviceBefore; + return info->immutableDevice.data(); } @@ -566,12 +567,15 @@ PartitionCoreModule::scanForEfiSystemPartitions() } PartitionCoreModule::DeviceInfo* -PartitionCoreModule::infoForDevice( Device* device ) const +PartitionCoreModule::infoForDevice( const Device* device ) const { - for ( auto deviceInfo : m_deviceInfos ) + for ( auto it = m_deviceInfos.constBegin(); + it != m_deviceInfos.constEnd(); ++it ) { - if ( deviceInfo->device.data() == device ) - return deviceInfo; + if ( ( *it )->device.data() == device ) + return *it; + if ( ( *it )->immutableDevice.data() == device ) + return *it; } return nullptr; } diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 3051f99b4..4a0d89afc 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -68,7 +68,7 @@ public: DeviceModel* deviceModel() const; - PartitionModel* partitionModelForDevice( Device* device ) const; + PartitionModel* partitionModelForDevice( const Device* device ) const; //HACK: all devices change over time, and together make up the state of the CoreModule. // However this makes it hard to show the *original* state of a device. @@ -77,7 +77,7 @@ public: // This should probably be redone some other way. // -- Teo 4/2015 //FIXME: make this horrible method private. -- Teo 12/2015 - static Device* createImmutableDeviceCopy( Device* device ); + Device* immutableDeviceCopy( const Device* device ); QAbstractItemModel* bootLoaderModel() const; @@ -147,6 +147,7 @@ private: ~DeviceInfo(); QScopedPointer< Device > device; QScopedPointer< PartitionModel > partitionModel; + const QScopedPointer< Device > immutableDevice; QList< Calamares::job_ptr > jobs; void forgetChanges(); @@ -166,7 +167,7 @@ private: void updateIsDirty(); void scanForEfiSystemPartitions(); - DeviceInfo* infoForDevice( Device* ) const; + DeviceInfo* infoForDevice( const Device* ) const; OsproberEntryList m_osproberLines; diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 2f4b9410a..daa64ce11 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -817,7 +817,7 @@ ChoicePage::updateDeviceStatePreview() m_beforePartitionLabelsView = new PartitionLabelsView( m_previewBeforeFrame ); m_beforePartitionLabelsView->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions ); - Device* deviceBefore = m_core->createImmutableDeviceCopy( currentDevice ); + Device* deviceBefore = m_core->immutableDeviceCopy( currentDevice ); PartitionModel* model = new PartitionModel( m_beforePartitionBarsView ); model->init( deviceBefore, m_core->osproberEntries() );