Merge pull request #5801 from guanqun/use-retain-for-memorydb

use rust 1.18's retain to boost the purge performance
This commit is contained in:
Robert Habermeier 2017-06-18 04:24:17 +02:00 committed by GitHub
commit e06d1dbb0c
2 changed files with 2 additions and 6 deletions

View File

@ -53,7 +53,7 @@ below to build from source.
## Build dependencies ## Build dependencies
**Parity requires Rust version 1.17.0 to build** **Parity requires Rust version 1.18.0 to build**
We recommend installing Rust through [rustup](https://www.rustup.rs/). If you don't already have rustup, you can install it like this: We recommend installing Rust through [rustup](https://www.rustup.rs/). If you don't already have rustup, you can install it like this:

View File

@ -103,11 +103,7 @@ impl MemoryDB {
/// Purge all zero-referenced data from the database. /// Purge all zero-referenced data from the database.
pub fn purge(&mut self) { pub fn purge(&mut self) {
let empties: Vec<_> = self.data.iter() self.data.retain(|_, &mut (_, rc)| rc != 0);
.filter(|&(_, &(_, rc))| rc == 0)
.map(|(k, _)| k.clone())
.collect();
for empty in empties { self.data.remove(&empty); }
} }
/// Return the internal map of hashes to data, clearing the current state. /// Return the internal map of hashes to data, clearing the current state.