From 8c79c981b112a53b58775e92a2d79e6d0bfd5b9a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Sep 2018 05:33:39 -0400 Subject: [PATCH] [partition] Simplify space calculations - Q_ASSERT doesn't work in constexpr functions because it's not - May as well calculate bytes at compile-time, no need to give the runaround via number-of-MiB --- src/modules/partition/core/PartitionActions.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 99c231b1b..7e488367f 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -83,10 +83,7 @@ swapSuggestion( const qint64 availableSpaceB ) constexpr qint64 alignBytesToBlockSize( qint64 bytes, qint64 blocksize ) { - Q_ASSERT( bytes >= 0 ); - Q_ASSERT( blocksize > 0 ); qint64 blocks = bytes / blocksize; - Q_ASSERT( blocks >= 0 ); if ( blocks * blocksize != bytes ) ++blocks; @@ -114,17 +111,17 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass // the logical sector size (usually 512B). EFI starts with 2MiB // empty and a 300MiB EFI boot partition, while BIOS starts at // the 1MiB boundary (usually sector 2048). - int uefisys_part_size = isEfi ? 300 : 0; - int empty_space_size = isEfi ? 2 : 1; + int uefisys_part_sizeB = isEfi ? 300_MiB : 0_MiB; + int empty_space_sizeB = isEfi ? 2_MiB : 1_MiB; // Since sectors count from 0, if the space is 2048 sectors in size, // the first free sector has number 2048 (and there are 2048 sectors // before that one, numbered 0..2047). - qint64 firstFreeSector = bytesToSectors( MiBtoBytes(empty_space_size), dev->logicalSize() ); + qint64 firstFreeSector = bytesToSectors( empty_space_sizeB, dev->logicalSize() ); if ( isEfi ) { - qint64 efiSectorCount = bytesToSectors( MiBtoBytes(uefisys_part_size), dev->logicalSize() ); + qint64 efiSectorCount = bytesToSectors( uefisys_part_sizeB, dev->logicalSize() ); Q_ASSERT( efiSectorCount > 0 ); // Since sectors count from 0, and this partition is created starting