From 4f1f4a39078203abd36566099cfff0a45223eda9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 29 Mar 2022 16:39:54 +0800 Subject: [PATCH] optimize journal resolution code We have the journals tracked in a HashSet, so, use the hashing properties instead of an O(N) search. --- services/pddb/src/backend/hw.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/services/pddb/src/backend/hw.rs b/services/pddb/src/backend/hw.rs index 4cd1c1204..4fe8a0e4a 100644 --- a/services/pddb/src/backend/hw.rs +++ b/services/pddb/src/backend/hw.rs @@ -451,12 +451,10 @@ impl PddbOs { /// Pages drawn from disk might already have come from the FSCB. We need to make the journal number /// of these consistent with those in the FSCB so later on when they are retired we don't have journal conflicts. fn resolve_pp_journal(&self, pp: &mut PhysPage) { - for fs_pp in self.fspace_cache.iter() { - if pp.page_number() == fs_pp.page_number() { - if pp.journal() < fs_pp.journal() { - log::debug!("bumping journal {}->{}: {:x?}", pp.journal(), fs_pp.journal(), pp); - pp.set_journal(fs_pp.journal()); - } + if let Some(fs_pp) = self.fspace_cache.get(pp) { + if pp.journal() < fs_pp.journal() { + log::debug!("bumping journal {}->{}: {:x?}", pp.journal(), fs_pp.journal(), pp); + pp.set_journal(fs_pp.journal()); } } }