Skip to content

Commit 30daa1d

Browse files
author
Markus Westerlind
committed
Split UnificationStore into a Mut variant which do not require snapshotting
1 parent 25f94c2 commit 30daa1d

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

src/unify/backing_vec.rs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use snapshot_vec as sv;
44
use std::marker::PhantomData;
55
use std::ops::{self, Range};
66

7-
use undo_log::{Rollback, Snapshots, VecLog};
7+
use undo_log::{Rollback, Snapshots, UndoLogs, VecLog};
88

99
use super::{UnifyKey, UnifyValue, VarValue};
1010

@@ -26,9 +26,7 @@ pub trait UnificationStoreBase: ops::Index<usize, Output = VarValue<Key<Self>>>
2626
}
2727
}
2828

29-
pub trait UnificationStore: UnificationStoreBase {
30-
type Snapshot;
31-
29+
pub trait UnificationStoreMut: UnificationStoreBase {
3230
fn reset_unifications(&mut self, value: impl FnMut(u32) -> VarValue<Self::Key>);
3331

3432
fn push(&mut self, value: VarValue<Self::Key>);
@@ -38,6 +36,10 @@ pub trait UnificationStore: UnificationStoreBase {
3836
fn update<F>(&mut self, index: usize, op: F)
3937
where
4038
F: FnOnce(&mut VarValue<Self::Key>);
39+
}
40+
41+
pub trait UnificationStore: UnificationStoreMut {
42+
type Snapshot;
4143

4244
fn start_snapshot(&mut self) -> Self::Snapshot;
4345

@@ -81,14 +83,12 @@ where
8183
}
8284
}
8385

84-
impl<K, V, L> UnificationStore for InPlace<K, V, L>
86+
impl<K, V, L> UnificationStoreMut for InPlace<K, V, L>
8587
where
8688
K: UnifyKey,
8789
V: sv::VecLike<Delegate<K>>,
88-
L: Snapshots<sv::UndoLog<Delegate<K>>>,
90+
L: UndoLogs<sv::UndoLog<Delegate<K>>>,
8991
{
90-
type Snapshot = sv::Snapshot<L::Snapshot>;
91-
9292
#[inline]
9393
fn reset_unifications(&mut self, mut value: impl FnMut(u32) -> VarValue<Self::Key>) {
9494
self.values.set_all(|i| value(i as u32));
@@ -111,6 +111,15 @@ where
111111
{
112112
self.values.update(index, op)
113113
}
114+
}
115+
116+
impl<K, V, L> UnificationStore for InPlace<K, V, L>
117+
where
118+
K: UnifyKey,
119+
V: sv::VecLike<Delegate<K>>,
120+
L: Snapshots<sv::UndoLog<Delegate<K>>>,
121+
{
122+
type Snapshot = sv::Snapshot<L::Snapshot>;
114123

115124
#[inline]
116125
fn start_snapshot(&mut self) -> Self::Snapshot {
@@ -188,27 +197,7 @@ impl<K: UnifyKey> UnificationStoreBase for Persistent<K> {
188197
}
189198

190199
#[cfg(feature = "persistent")]
191-
impl<K: UnifyKey> UnificationStore for Persistent<K> {
192-
type Snapshot = Self;
193-
194-
#[inline]
195-
fn start_snapshot(&mut self) -> Self::Snapshot {
196-
self.clone()
197-
}
198-
199-
#[inline]
200-
fn rollback_to(&mut self, snapshot: Self::Snapshot) {
201-
*self = snapshot;
202-
}
203-
204-
#[inline]
205-
fn commit(&mut self, _snapshot: Self::Snapshot) {}
206-
207-
#[inline]
208-
fn values_since_snapshot(&self, snapshot: &Self::Snapshot) -> Range<usize> {
209-
snapshot.len()..self.len()
210-
}
211-
200+
impl<K: UnifyKey> UnificationStoreMut for Persistent<K> {
212201
#[inline]
213202
fn reset_unifications(&mut self, mut value: impl FnMut(u32) -> VarValue<Self::Key>) {
214203
// Without extending dogged, there isn't obviously a more
@@ -239,6 +228,29 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
239228
}
240229
}
241230

231+
#[cfg(feature = "persistent")]
232+
impl<K: UnifyKey> UnificationStore for Persistent<K> {
233+
type Snapshot = Self;
234+
235+
#[inline]
236+
fn start_snapshot(&mut self) -> Self::Snapshot {
237+
self.clone()
238+
}
239+
240+
#[inline]
241+
fn rollback_to(&mut self, snapshot: Self::Snapshot) {
242+
*self = snapshot;
243+
}
244+
245+
#[inline]
246+
fn commit(&mut self, _snapshot: Self::Snapshot) {}
247+
248+
#[inline]
249+
fn values_since_snapshot(&self, snapshot: &Self::Snapshot) -> Range<usize> {
250+
snapshot.len()..self.len()
251+
}
252+
}
253+
242254
#[cfg(feature = "persistent")]
243255
impl<K> ops::Index<usize> for Persistent<K>
244256
where

src/unify/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use snapshot_vec::{self as sv, UndoLog};
3939
use undo_log::{UndoLogs, VecLog};
4040

4141
mod backing_vec;
42-
pub use self::backing_vec::{Delegate, InPlace, UnificationStore, UnificationStoreBase};
42+
pub use self::backing_vec::{
43+
Delegate, InPlace, UnificationStore, UnificationStoreBase, UnificationStoreMut,
44+
};
4345

4446
#[cfg(feature = "persistent")]
4547
pub use self::backing_vec::Persistent;
@@ -312,7 +314,7 @@ impl<S: UnificationStoreBase> UnificationTable<S> {
312314
}
313315
}
314316

315-
impl<S: UnificationStore> UnificationTable<S> {
317+
impl<S: UnificationStoreMut> UnificationTable<S> {
316318
/// Starts a new snapshot. Each snapshot must be either
317319
/// Creates a fresh key with the given value.
318320
pub fn new_key(&mut self, value: S::Value) -> S::Key {
@@ -465,7 +467,7 @@ impl<S: UnificationStore> UnificationTable<S> {
465467
466468
impl<S, K, V> UnificationTable<S>
467469
where
468-
S: UnificationStore<Key = K, Value = V>,
470+
S: UnificationStoreMut<Key = K, Value = V>,
469471
K: UnifyKey<Value = V>,
470472
V: UnifyValue,
471473
{

0 commit comments

Comments
 (0)