From 9a87b7b17710c9ab9f198d1cd1d3e69a4390b5f7 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 13 Feb 2024 13:33:16 -0500 Subject: [PATCH] Update some structure memory layour based on pahole feedback, see if we gain RAM --- src/credentials/FabricTable.h | 16 ++++++++-------- src/lib/dnssd/TxtFields.h | 34 +++++++++++++++++----------------- src/lib/dnssd/Types.h | 12 ++++++------ 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/credentials/FabricTable.h b/src/credentials/FabricTable.h index 688a6d6a612bc7..c61b6176fecb1e 100644 --- a/src/credentials/FabricTable.h +++ b/src/credentials/FabricTable.h @@ -116,15 +116,15 @@ class DLL_EXPORT FabricInfo private: struct InitParams { - NodeId nodeId = kUndefinedNodeId; - FabricId fabricId = kUndefinedFabricId; - FabricIndex fabricIndex = kUndefinedFabricIndex; - CompressedFabricId compressedFabricId = kUndefinedCompressedFabricId; - Crypto::P256PublicKey rootPublicKey; - VendorId vendorId = VendorId::NotSpecified; /**< Vendor ID for commissioner of fabric */ + CompressedFabricId compressedFabricId = kUndefinedCompressedFabricId; + NodeId nodeId = kUndefinedNodeId; + FabricIndex fabricIndex = kUndefinedFabricIndex; Crypto::P256Keypair * operationalKeypair = nullptr; - bool hasExternallyOwnedKeypair = false; - bool advertiseIdentity = false; + FabricId fabricId = kUndefinedFabricId; + Crypto::P256PublicKey rootPublicKey; + VendorId vendorId = VendorId::NotSpecified; /**< Vendor ID for commissioner of fabric */ + bool hasExternallyOwnedKeypair = false; + bool advertiseIdentity = false; CHIP_ERROR AreValid() const { diff --git a/src/lib/dnssd/TxtFields.h b/src/lib/dnssd/TxtFields.h index c3b8a0d668682c..5546493624119d 100644 --- a/src/lib/dnssd/TxtFields.h +++ b/src/lib/dnssd/TxtFields.h @@ -79,28 +79,28 @@ enum class TxtFieldKey : uint8_t namespace Internal { struct TxtFieldInfo { - TxtFieldKey key; size_t valMaxSize; - char keyStr[4]; + TxtFieldKey key; TxtKeyUse use; + char keyStr[4]; }; constexpr const TxtFieldInfo txtFieldInfo[static_cast(TxtFieldKey::kCount)] = { - { TxtFieldKey::kUnknown, 0, "", TxtKeyUse::kNone }, - { TxtFieldKey::kLongDiscriminator, kKeyLongDiscriminatorMaxLength, "D", TxtKeyUse::kCommission }, - { TxtFieldKey::kVendorProduct, kKeyVendorProductMaxLength, "VP", TxtKeyUse::kCommission }, - { TxtFieldKey::kCommissioningMode, kKeyCommissioningModeMaxLength, "CM", TxtKeyUse::kCommission }, - { TxtFieldKey::kDeviceType, kKeyDeviceTypeMaxLength, "DT", TxtKeyUse::kCommission }, - { TxtFieldKey::kDeviceName, kKeyDeviceNameMaxLength, "DN", TxtKeyUse::kCommission }, - { TxtFieldKey::kRotatingDeviceId, kKeyRotatingDeviceIdMaxLength, "RI", TxtKeyUse::kCommission }, - { TxtFieldKey::kPairingInstruction, kKeyPairingInstructionMaxLength, "PI", TxtKeyUse::kCommission }, - { TxtFieldKey::kPairingHint, kKeyPairingHintMaxLength, "PH", TxtKeyUse::kCommission }, - { TxtFieldKey::kCommissionerPasscode, kKeyCommissionerPasscodeMaxLength, "CP", TxtKeyUse::kCommission }, - { TxtFieldKey::kSessionIdleInterval, kKeySessionIdleIntervalMaxLength, "SII", TxtKeyUse::kCommon }, - { TxtFieldKey::kSessionActiveInterval, kKeySessionActiveIntervalMaxLength, "SAI", TxtKeyUse::kCommon }, - { TxtFieldKey::kSessionActiveThreshold, kKeySessionActiveThresholdMaxLength, "SAT", TxtKeyUse::kCommon }, - { TxtFieldKey::kTcpSupported, kKeyTcpSupportedMaxLength, "T", TxtKeyUse::kCommon }, - { TxtFieldKey::kLongIdleTimeICD, kKeyLongIdleTimeICDMaxLength, "ICD", TxtKeyUse::kCommon }, + { 0, TxtFieldKey::kUnknown, TxtKeyUse::kNone, "" }, + { kKeyLongDiscriminatorMaxLength, TxtFieldKey::kLongDiscriminator, TxtKeyUse::kCommission, "D" }, + { kKeyVendorProductMaxLength, TxtFieldKey::kVendorProduct, TxtKeyUse::kCommission, "VP" }, + { kKeyCommissioningModeMaxLength, TxtFieldKey::kCommissioningMode, TxtKeyUse::kCommission, "CM" }, + { kKeyDeviceTypeMaxLength, TxtFieldKey::kDeviceType, TxtKeyUse::kCommission, "DT" }, + { kKeyDeviceNameMaxLength, TxtFieldKey::kDeviceName, TxtKeyUse::kCommission, "DN" }, + { kKeyRotatingDeviceIdMaxLength, TxtFieldKey::kRotatingDeviceId, TxtKeyUse::kCommission, "RI" }, + { kKeyPairingInstructionMaxLength, TxtFieldKey::kPairingInstruction, TxtKeyUse::kCommission, "PI" }, + { kKeyPairingHintMaxLength, TxtFieldKey::kPairingHint, TxtKeyUse::kCommission, "PH" }, + { kKeyCommissionerPasscodeMaxLength, TxtFieldKey::kCommissionerPasscode, TxtKeyUse::kCommission, "CP" }, + { kKeySessionIdleIntervalMaxLength, TxtFieldKey::kSessionIdleInterval, TxtKeyUse::kCommon, "SII" }, + { kKeySessionActiveIntervalMaxLength, TxtFieldKey::kSessionActiveInterval, TxtKeyUse::kCommon, "SAI" }, + { kKeySessionActiveThresholdMaxLength, TxtFieldKey::kSessionActiveThreshold, TxtKeyUse::kCommon, "SAT" }, + { kKeyTcpSupportedMaxLength, TxtFieldKey::kTcpSupported, TxtKeyUse::kCommon, "T" }, + { kKeyLongIdleTimeICDMaxLength, TxtFieldKey::kLongIdleTimeICD, TxtKeyUse::kCommon, "ICD" }, }; #ifdef CHIP_CONFIG_TEST diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index 5d78c7631223cf..06a7352d60d919 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -207,18 +207,18 @@ inline constexpr size_t kMaxPairingInstructionLen = 128; /// Data that is specific to commisionable/commissioning node discovery struct CommissionNodeData { - char instanceName[Commission::kInstanceNameMaxLength + 1] = {}; + size_t rotatingIdLen = 0; + uint32_t deviceType = 0; uint16_t longDiscriminator = 0; uint16_t vendorId = 0; uint16_t productId = 0; + uint16_t pairingHint = 0; uint8_t commissioningMode = 0; - uint32_t deviceType = 0; - char deviceName[kMaxDeviceNameLen + 1] = {}; + uint8_t commissionerPasscode = 0; uint8_t rotatingId[kMaxRotatingIdLen] = {}; - size_t rotatingIdLen = 0; - uint16_t pairingHint = 0; + char instanceName[Commission::kInstanceNameMaxLength + 1] = {}; + char deviceName[kMaxDeviceNameLen + 1] = {}; char pairingInstruction[kMaxPairingInstructionLen + 1] = {}; - uint8_t commissionerPasscode = 0; CommissionNodeData() {}