From 7d189905ba1c1781612406acfcfb4fe7e9ab8fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hatcher?= Date: Sat, 9 Mar 2024 14:31:03 +0100 Subject: [PATCH] UPDATE: Skeleton for the garbage collector --- base/src/garbage_collector.rs | 12 ++++++++++++ base/src/lib.rs | 1 + base/src/test/mod.rs | 1 + base/src/test/test_gc.rs | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 base/src/garbage_collector.rs create mode 100644 base/src/test/test_gc.rs diff --git a/base/src/garbage_collector.rs b/base/src/garbage_collector.rs new file mode 100644 index 0000000..e4bfc58 --- /dev/null +++ b/base/src/garbage_collector.rs @@ -0,0 +1,12 @@ +use crate::model::Model; + +// The gc (Garbage Collector) cleans up leftover elements in the workbook: +// * Strings that are no longe reachable +// * Styles that are no longer reachable +// * ... + +impl Model { + pub(crate) fn gc(&mut self) -> Result<(), String> { + todo!() + } +} \ No newline at end of file diff --git a/base/src/lib.rs b/base/src/lib.rs index e16f282..c7a84c1 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -50,6 +50,7 @@ mod implicit_intersection; mod units; mod utils; mod workbook; +mod garbage_collector; #[cfg(test)] mod test; diff --git a/base/src/test/mod.rs b/base/src/test/mod.rs index a33aa35..bc1d280 100644 --- a/base/src/test/mod.rs +++ b/base/src/test/mod.rs @@ -53,3 +53,4 @@ mod test_frozen_rows_and_columns; mod test_get_cell_content; mod test_percentage; mod test_today; +mod test_gc; diff --git a/base/src/test/test_gc.rs b/base/src/test/test_gc.rs new file mode 100644 index 0000000..9261bbe --- /dev/null +++ b/base/src/test/test_gc.rs @@ -0,0 +1,22 @@ +#![allow(clippy::unwrap_used)] + +use crate::test::util::new_empty_model; + +#[test] +fn test_empty_model() { + let mut model = new_empty_model(); + // set a string + model._set("A1", "Hello"); + assert_eq!(model.shared_strings.len(), 1); + // calling the gc doesn't do anything + model.gc().unwrap(); + assert_eq!(model.shared_strings.len(), 1); + + // If we delete the cell the string is still in the list + model.delete_cell(0, 1, 1).unwrap(); + assert_eq!(model.shared_strings.len(), 1); + + // after the gc the string is no longer present + model.gc().unwrap(); + assert_eq!(model.shared_strings.len(), 0); +} \ No newline at end of file