perf(trie): use unstable sort when sorting for computing roots (#11301)

This commit is contained in:
DaniPopes
2024-09-27 20:37:23 +02:00
committed by GitHub
parent 6c92f8a26d
commit d8f16b83b7

View File

@ -75,7 +75,7 @@ pub fn state_root_unhashed<A: Into<TrieAccount>>(
pub fn state_root_unsorted<A: Into<TrieAccount>>(
state: impl IntoIterator<Item = (B256, A)>,
) -> B256 {
state_root(state.into_iter().sorted_by_key(|(key, _)| *key))
state_root(state.into_iter().sorted_unstable_by_key(|(key, _)| *key))
}
/// Calculates the root hash of the state represented as MPT.
@ -105,7 +105,7 @@ pub fn storage_root_unhashed(storage: impl IntoIterator<Item = (B256, U256)>) ->
/// Sorts and calculates the root hash of account storage trie.
/// See [`storage_root`] for more info.
pub fn storage_root_unsorted(storage: impl IntoIterator<Item = (B256, U256)>) -> B256 {
storage_root(storage.into_iter().sorted_by_key(|(key, _)| *key))
storage_root(storage.into_iter().sorted_unstable_by_key(|(key, _)| *key))
}
/// Calculates the root hash of account storage trie.