Skip to content

Commit f54589c

Browse files
Seulgi Kimsgkim126
authored andcommitted
Cleanup ArchiveDB::keys()
And it adds an assetion that the reference count of the overlay cannot be less than -1.
1 parent 1679d30 commit f54589c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

util/journaldb/src/archivedb.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2+
// Copyright 2019 Kodebox, Inc.
23
// This file is part of Parity.
34

45
// Parity is free software: you can redistribute it and/or modify
@@ -23,7 +24,6 @@ use hashdb::*;
2324
use kvdb::{DBTransaction, KeyValueDB};
2425
use primitives::{Bytes, H256};
2526
use rlp::{decode, encode};
26-
use std::collections::hash_map::Entry;
2727
use std::collections::HashMap;
2828
use std::sync::Arc;
2929

@@ -72,14 +72,9 @@ impl HashDB for ArchiveDB {
7272
self.backing.iter(self.column).map(|(key, _)| (H256::from_slice(&*key), 1)).collect();
7373

7474
for (key, refs) in self.overlay.keys() {
75-
match ret.entry(key) {
76-
Entry::Occupied(mut entry) => {
77-
*entry.get_mut() += refs;
78-
}
79-
Entry::Vacant(entry) => {
80-
entry.insert(refs);
81-
}
82-
}
75+
let rc = ret.entry(key).or_default();
76+
*rc += refs;
77+
assert!(*rc >= -1, "rc should be equal to or greater than -1, but {}", rc);
8378
}
8479
ret
8580
}

0 commit comments

Comments
 (0)