From 94b1490b7b906b90e743512edd305302ed96ce0f Mon Sep 17 00:00:00 2001 From: Gilles Moris Date: Wed, 15 May 2019 07:07:21 +0200 Subject: [PATCH] Create a constant unusedPartType object instead of recreating it each time --- gptcl.cc | 2 +- gptpart.cc | 4 ++-- parttypes.cc | 1 + parttypes.h | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gptcl.cc b/gptcl.cc index 6c36738..bd80984 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -375,7 +375,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { partNum = newPartNum; if ((partNum >= 0) && (partNum < (int) GetNumParts())) { typeHelper = GetString(typeCode, 2); - if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") && + if ((typeHelper != PartType::unusedPartType) && (ChangePartType(partNum, typeHelper))) { saveData = 1; } else { diff --git a/gptpart.cc b/gptpart.cc index 56415e1..b4f2698 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -434,7 +434,7 @@ void GPTPart::ReversePartBytes(void) { void GPTPart::ChangeType(void) { string line; int changeName; - PartType tempType = (GUIDData) "00000000-0000-0000-0000-000000000000"; + PartType tempType = PartType::unusedPartType; #ifdef USE_UTF16 changeName = (GetDescription() == GetUTypeName()); @@ -454,7 +454,7 @@ void GPTPart::ChangeType(void) { else tempType = line; } // if/else - } while (tempType == (GUIDData) "00000000-0000-0000-0000-000000000000"); + } while (tempType == PartType::unusedPartType); partitionType = tempType; cout << "Changed type of partition to '" << partitionType.TypeName() << "'\n"; if (changeName) { diff --git a/parttypes.cc b/parttypes.cc index cd225d1..1b32569 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -19,6 +19,7 @@ using namespace std; int PartType::numInstances = 0; AType* PartType::allTypes = NULL; AType* PartType::lastType = NULL; +const PartType PartType::unusedPartType = (GUIDData) "00000000-0000-0000-0000-000000000000"; // Constructor. Its main task is to initialize the data list, but only // if this is the first instance, since it's a static linked list. diff --git a/parttypes.h b/parttypes.h index c108a17..2b80026 100644 --- a/parttypes.h +++ b/parttypes.h @@ -36,6 +36,9 @@ protected: static AType* lastType; // Pointer to last entry in the list void AddAllTypes(void); public: + // PartType with GUID "00000000-0000-0000-0000-000000000000" + static const PartType unusedPartType; + PartType(void); PartType(const PartType & orig); PartType(const GUIDData & orig);