History

Try reusing mappings, but no LRU(#266)

Sebastian Thiel committed 4 years ago

Commit bb602e81 parent 2d6960f3 files · +7 −24Browse files

Unified · Split

3 files
  1. git-odb/src/store/general/find.rs +5 −15
  2. git-odb/src/store/general/handle.rs +2 −8
  3. git-odb/src/store/general/mod.rs +0 −1
git-odb/src/store/general/find.rs+5−15
@@ -15,22 +15,13 @@ where · 14 unmodified lines
15 fn contains(&self, id: impl AsRef<oid>) -> bool {15 fn contains(&self, id: impl AsRef<oid>) -> bool {
16 let id = id.as_ref();16 let id = id.as_ref();
17 loop {17 loop {
18 {18 let snapshot = self.snapshot.borrow();
19 let mut indices = self.indices.borrow_mut();19 for index in &snapshot.indices {
20 let mut iter = indices.iter();20 if index.contains(id) {
21 let mut idx = 0;21 return true;
22 while let Some(index) = iter.next() {
23 if index.contains(id) {
24 if idx != 0 {
25 indices.swap(0, idx);
26 }
27 return true;
28 }
29 idx += 1;
30 }22 }
31 }23 }
32 24
33 let snapshot = self.snapshot.borrow();
34 for lodb in snapshot.loose_dbs.iter() {25 for lodb in snapshot.loose_dbs.iter() {
35 if lodb.contains(id) {26 if lodb.contains(id) {
36 return true;27 return true;
@@ -38,9 +29,8 @@ where · 1 unmodified line
38 }29 }
39 30
40 match self.store.load_one_index(self.refresh_mode, &snapshot.marker) {31 match self.store.load_one_index(self.refresh_mode, &snapshot.marker) {
41 Ok(Some(load_index::Outcome::Replace(mut new_snapshot))) => {32 Ok(Some(load_index::Outcome::Replace(new_snapshot))) => {
42 drop(snapshot);33 drop(snapshot);
43 *self.indices.borrow_mut() = std::mem::take(&mut new_snapshot.indices);
44 *self.snapshot.borrow_mut() = new_snapshot;34 *self.snapshot.borrow_mut() = new_snapshot;
45 }35 }
46 Ok(None) => return false, // nothing more to load, or our refresh mode doesn't allow disk refreshes36 Ok(None) => return false, // nothing more to load, or our refresh mode doesn't allow disk refreshes
git-odb/src/store/general/handle.rs+2−8
@@ -123,14 +123,11 @@ impl super::Store { · 122 unmodified lines
123 refresh_mode: crate::RefreshMode,123 refresh_mode: crate::RefreshMode,
124 ) -> super::Handle<OwnShared<super::Store>> {124 ) -> super::Handle<OwnShared<super::Store>> {
125 let token = self.register_handle();125 let token = self.register_handle();
126 let mut snapshot = self.collect_snapshot();
127 let indices = RefCell::new(std::mem::take(&mut snapshot.indices));
128 super::Handle {126 super::Handle {
129 store: self.clone(),127 store: self.clone(),
130 refresh_mode,128 refresh_mode,
131 token: Some(token),129 token: Some(token),
132 snapshot: RefCell::new(snapshot),130 snapshot: RefCell::new(self.collect_snapshot()),
133 indices,
134 }131 }
135 }132 }
136}133}
@@ -167,14 +164,11 @@ where · 30 unmodified lines
167 S: Deref<Target = super::Store> + Clone,164 S: Deref<Target = super::Store> + Clone,
168{165{
169 fn clone(&self) -> Self {166 fn clone(&self) -> Self {
170 let mut snapshot = self.store.collect_snapshot();
171 let indices = RefCell::new(std::mem::take(&mut snapshot.indices));
172 super::Handle {167 super::Handle {
173 store: self.store.clone(),168 store: self.store.clone(),
174 refresh_mode: self.refresh_mode,169 refresh_mode: self.refresh_mode,
175 token: self.store.register_handle().into(),170 token: self.store.register_handle().into(),
176 snapshot: RefCell::new(snapshot),171 snapshot: RefCell::new(self.store.collect_snapshot()),
177 indices,
178 }172 }
179 }173 }
180}174}
git-odb/src/store/general/mod.rs+0−1
@@ -16,7 +16,6 @@ where · 15 unmodified lines
16 16
17 pub(crate) token: Option<handle::Mode>,17 pub(crate) token: Option<handle::Mode>,
18 snapshot: RefCell<load_index::Snapshot>,18 snapshot: RefCell<load_index::Snapshot>,
19 indices: RefCell<Vec<handle::IndexLookup>>,
20}19}
21 20
22pub struct Store {21pub struct Store {