diff options
| author | ljedrz <ljedrz@gmail.com> | 2018-08-09 16:57:55 +0200 |
|---|---|---|
| committer | ljedrz <ljedrz@gmail.com> | 2018-08-09 19:50:11 +0200 |
| commit | ffdac5d592194e7026d3e5fc03bce896c3086cd7 (patch) | |
| tree | c1f6b754d4f19bed924c6407ebd6c8e614e8c6f1 /src/librustc_data_structures | |
| parent | 76b69a604ee0d70be1edfa2828c769dc1b148d13 (diff) | |
| download | rust-ffdac5d592194e7026d3e5fc03bce896c3086cd7.tar.gz rust-ffdac5d592194e7026d3e5fc03bce896c3086cd7.zip | |
Make SnapshotMap::{commit, rollback_to} take references
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/snapshot_map/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustc_data_structures/snapshot_map/test.rs | 8 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index 6ee8c3579f5..5030bf98dff 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -92,7 +92,7 @@ impl<K, V> SnapshotMap<K, V> pub fn snapshot(&mut self) -> Snapshot { self.undo_log.push(UndoLog::OpenSnapshot); let len = self.undo_log.len() - 1; - Snapshot { len: len } + Snapshot { len } } fn assert_open_snapshot(&self, snapshot: &Snapshot) { @@ -103,8 +103,8 @@ impl<K, V> SnapshotMap<K, V> }); } - pub fn commit(&mut self, snapshot: Snapshot) { - self.assert_open_snapshot(&snapshot); + pub fn commit(&mut self, snapshot: &Snapshot) { + self.assert_open_snapshot(snapshot); if snapshot.len == 0 { // The root snapshot. self.undo_log.truncate(0); @@ -135,8 +135,8 @@ impl<K, V> SnapshotMap<K, V> } } - pub fn rollback_to(&mut self, snapshot: Snapshot) { - self.assert_open_snapshot(&snapshot); + pub fn rollback_to(&mut self, snapshot: &Snapshot) { + self.assert_open_snapshot(snapshot); while self.undo_log.len() > snapshot.len + 1 { let entry = self.undo_log.pop().unwrap(); self.reverse(entry); diff --git a/src/librustc_data_structures/snapshot_map/test.rs b/src/librustc_data_structures/snapshot_map/test.rs index 4114082839b..b163e0fe420 100644 --- a/src/librustc_data_structures/snapshot_map/test.rs +++ b/src/librustc_data_structures/snapshot_map/test.rs @@ -20,7 +20,7 @@ fn basic() { map.insert(44, "fourty-four"); assert_eq!(map[&44], "fourty-four"); assert_eq!(map.get(&33), None); - map.rollback_to(snapshot); + map.rollback_to(&snapshot); assert_eq!(map[&22], "twenty-two"); assert_eq!(map.get(&33), None); assert_eq!(map.get(&44), None); @@ -33,7 +33,7 @@ fn out_of_order() { map.insert(22, "twenty-two"); let snapshot1 = map.snapshot(); let _snapshot2 = map.snapshot(); - map.rollback_to(snapshot1); + map.rollback_to(&snapshot1); } #[test] @@ -43,8 +43,8 @@ fn nested_commit_then_rollback() { let snapshot1 = map.snapshot(); let snapshot2 = map.snapshot(); map.insert(22, "thirty-three"); - map.commit(snapshot2); + map.commit(&snapshot2); assert_eq!(map[&22], "thirty-three"); - map.rollback_to(snapshot1); + map.rollback_to(&snapshot1); assert_eq!(map[&22], "twenty-two"); } |
