summaryrefslogtreecommitdiffstats
path: root/vendor/gix/src/repository/cache.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix/src/repository/cache.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/repository/cache.rs')
-rw-r--r--vendor/gix/src/repository/cache.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/gix/src/repository/cache.rs b/vendor/gix/src/repository/cache.rs
new file mode 100644
index 000000000..7dcd844e6
--- /dev/null
+++ b/vendor/gix/src/repository/cache.rs
@@ -0,0 +1,30 @@
+/// Configure how caches are used to speed up various git repository operations
+impl crate::Repository {
+ /// Sets the amount of space used at most for caching most recently accessed fully decoded objects, to `Some(bytes)`,
+ /// or `None` to deactivate it entirely.
+ ///
+ /// Note that it is unset by default but can be enabled once there is time for performance optimization.
+ /// Well-chosen cache sizes can improve performance particularly if objects are accessed multiple times in a row.
+ /// The cache is configured to grow gradually.
+ ///
+ /// Note that a cache on application level should be considered as well as the best object access is not doing one.
+ pub fn object_cache_size(&mut self, bytes: impl Into<Option<usize>>) {
+ let bytes = bytes.into();
+ match bytes {
+ Some(bytes) if bytes == 0 => self.objects.unset_object_cache(),
+ Some(bytes) => self
+ .objects
+ .set_object_cache(move || Box::new(crate::object::cache::MemoryCappedHashmap::new(bytes))),
+ None => self.objects.unset_object_cache(),
+ }
+ }
+
+ /// Set an object cache of size `bytes` if none is set.
+ ///
+ /// Use this method to avoid overwriting any existing value while assuring better performance in case no value is set.
+ pub fn object_cache_size_if_unset(&mut self, bytes: usize) {
+ if !self.objects.has_object_cache() {
+ self.object_cache_size(bytes)
+ }
+ }
+}