@@ -54,23 +54,27 @@ void CSimplifiedMNListEntry::ToJson(UniValue& obj) const
5454
5555CSimplifiedMNList::CSimplifiedMNList (const std::vector<CSimplifiedMNListEntry>& smlEntries)
5656{
57- mnList = smlEntries;
57+ mnList.resize (smlEntries.size ());
58+ for (size_t i = 0 ; i < smlEntries.size (); i++) {
59+ mnList[i] = std::make_unique<CSimplifiedMNListEntry>(smlEntries[i]);
60+ }
5861
59- std::sort (mnList.begin (), mnList.end (), [&](const CSimplifiedMNListEntry& a, const CSimplifiedMNListEntry& b) {
60- return a. proRegTxHash .Compare (b. proRegTxHash ) < 0 ;
62+ std::sort (mnList.begin (), mnList.end (), [&](const std::unique_ptr< CSimplifiedMNListEntry> & a, const std::unique_ptr< CSimplifiedMNListEntry> & b) {
63+ return a-> proRegTxHash .Compare (b-> proRegTxHash ) < 0 ;
6164 });
6265}
6366
6467CSimplifiedMNList::CSimplifiedMNList (const CDeterministicMNList& dmnList)
6568{
66- mnList.reserve (dmnList.GetAllMNsCount ());
69+ mnList.resize (dmnList.GetAllMNsCount ());
6770
68- dmnList.ForEachMN (false , [this ](const CDeterministicMNCPtr& dmn) {
69- mnList.emplace_back (*dmn);
71+ size_t i = 0 ;
72+ dmnList.ForEachMN (false , [this , &i](const CDeterministicMNCPtr& dmn) {
73+ mnList[i++] = std::make_unique<CSimplifiedMNListEntry>(*dmn);
7074 });
7175
72- std::sort (mnList.begin (), mnList.end (), [&](const CSimplifiedMNListEntry& a, const CSimplifiedMNListEntry& b) {
73- return a. proRegTxHash .Compare (b. proRegTxHash ) < 0 ;
76+ std::sort (mnList.begin (), mnList.end (), [&](const std::unique_ptr< CSimplifiedMNListEntry> & a, const std::unique_ptr< CSimplifiedMNListEntry> & b) {
77+ return a-> proRegTxHash .Compare (b-> proRegTxHash ) < 0 ;
7478 });
7579}
7680
@@ -79,7 +83,7 @@ uint256 CSimplifiedMNList::CalcMerkleRoot(bool* pmutated) const
7983 std::vector<uint256> leaves;
8084 leaves.reserve (mnList.size ());
8185 for (const auto & e : mnList) {
82- leaves.emplace_back (e. CalcHash ());
86+ leaves.emplace_back (e-> CalcHash ());
8387 }
8488 return ComputeMerkleRoot (leaves, pmutated);
8589}
0 commit comments