Skip to content

Commit

Permalink
reduce allocation of list of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 2, 2024
1 parent a718378 commit 93a4d1a
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ internal EchonetObjectSpecification(byte classGroupCode, byte classCode)
SpecificationMaster.GetInstance().DeviceClasses.FirstOrDefault(p => p.Code == classGroupCode) ??
throw new ArgumentException($"unknown class group: 0x{classGroupCode:X2}");

var properties = new List<EchonetPropertySpecification>();
const int MaxNumberOfProperty = 0x80; // EPC: 0b_1XXX_XXXX (0x80~0xFF)

var properties = new List<EchonetPropertySpecification>(capacity: MaxNumberOfProperty);

//スーパークラスのプロパティを列挙
using (var stream = SpecificationMaster.GetSpecificationMasterDataStream($"{ClassGroup.SuperClassName}.json"))
Expand Down Expand Up @@ -69,6 +71,8 @@ internal EchonetObjectSpecification(byte classGroupCode, byte classCode)
}
}

properties.TrimExcess(); // reduce capacity

Properties = properties;
}

Expand Down

0 comments on commit 93a4d1a

Please sign in to comment.