From bdf2602e7cd87d8420711b941df3ab14c1b13676 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 26 Oct 2024 00:30:32 +0200 Subject: [PATCH] hashindex: simplify .get --- src/borg/hashindex.pyx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/borg/hashindex.pyx b/src/borg/hashindex.pyx index 71a44d5cb..e188fe1b2 100644 --- a/src/borg/hashindex.pyx +++ b/src/borg/hashindex.pyx @@ -46,17 +46,14 @@ class ChunkIndex: def iteritems(self): yield from self.ht.iteritems() + def get(self, key, default=None): + return self.ht.get(key, default) + def add(self, key, refs, size): v = self.get(key, ChunkIndexEntry(0, 0)) refcount = min(self.MAX_VALUE, v.refcount + refs) self[key] = v._replace(refcount=refcount, size=size) - def get(self, key, default=None): - try: - return self[key] - except KeyError: - return default - def compact(self): return 0 @@ -100,10 +97,7 @@ class FuseVersionsIndex: return len(self.ht) def get(self, key, default=None): - try: - return self[key] - except KeyError: - return default + return self.ht.get(key, default) NSIndex1Entry = namedtuple('NSIndex1Entry', 'segment offset') @@ -143,10 +137,7 @@ class NSIndex1: return len(self.ht) def get(self, key, default=None): - try: - return self[key] - except KeyError: - return default + return self.ht.get(key, default) def pop(self, key, default=_NoDefault): try: