Skip to content

Commit 9a762ef

Browse files
committed
[txpackages] use std::lexicographical_compare instead of sorting hex strings
No behavior change, but getting the hex string is more expensive than necessary.
1 parent 8496f69 commit 9a762ef

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/policy/packages.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ uint256 GetPackageHash(const std::vector<CTransactionRef>& transactions)
156156
[](const auto& tx){ return tx->GetWitnessHash(); });
157157

158158
// Sort in ascending order
159-
std::sort(wtxids_copy.begin(), wtxids_copy.end(), [](const auto& lhs, const auto& rhs) { return lhs.GetHex() < rhs.GetHex(); });
159+
std::sort(wtxids_copy.begin(), wtxids_copy.end(), [](const auto& lhs, const auto& rhs) {
160+
return std::lexicographical_compare(std::make_reverse_iterator(lhs.end()), std::make_reverse_iterator(lhs.begin()),
161+
std::make_reverse_iterator(rhs.end()), std::make_reverse_iterator(rhs.begin()));
162+
});
160163

161164
// Get sha256 hash of the wtxids concatenated in this order
162165
HashWriter hashwriter;

0 commit comments

Comments
 (0)