Skip to content

Commit 7d53cb0

Browse files
HoOngEemergify[bot]
authored andcommitted
Reduce booting time by using is_empty method
1 parent 3b9d242 commit 7d53cb0

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

core/src/scheme/scheme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Scheme {
249249
}
250250

251251
pub fn check_genesis_root(&self, db: &HashDB) -> bool {
252-
if db.keys().is_empty() {
252+
if db.is_empty() {
253253
return true
254254
}
255255
db.contains(&self.state_root())

util/hashdb/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub trait HashDB: AsHashDB + Send + Sync {
4848
/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may
4949
/// happen without the data being eventually being inserted into the DB. It can be "owed" more than once.
5050
fn remove(&mut self, key: &H256);
51+
52+
/// check if the db has no commits
53+
fn is_empty(&self) -> bool;
5154
}
5255

5356
/// Upcast trait.

util/journaldb/src/archivedb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ impl HashDB for ArchiveDB {
102102
fn remove(&mut self, key: &H256) {
103103
self.overlay.remove(key);
104104
}
105+
106+
fn is_empty(&self) -> bool {
107+
self.latest_era.is_none()
108+
}
105109
}
106110

107111
impl JournalDB for ArchiveDB {
@@ -114,10 +118,6 @@ impl JournalDB for ArchiveDB {
114118
})
115119
}
116120

117-
fn is_empty(&self) -> bool {
118-
self.latest_era.is_none()
119-
}
120-
121121
fn latest_era(&self) -> Option<u64> {
122122
self.latest_era
123123
}

util/journaldb/src/traits.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ pub trait JournalDB: HashDB {
3535
0
3636
}
3737

38-
/// Check if this database has any commits
39-
fn is_empty(&self) -> bool;
40-
4138
/// Get the earliest era in the DB. None if there isn't yet any data in there.
4239
fn earliest_era(&self) -> Option<u64> {
4340
None

util/memorydb/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ impl HashDB for MemoryDB {
262262
}
263263
}
264264
}
265+
266+
fn is_empty(&self) -> bool {
267+
self.data.is_empty()
268+
}
265269
}
266270

267271
#[cfg(test)]

0 commit comments

Comments
 (0)