1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-03 05:35:58 +00:00

hashindex: simplify .get

This commit is contained in:
Thomas Waldmann 2024-10-26 00:30:32 +02:00
parent d2fe067647
commit bdf2602e7c
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -46,17 +46,14 @@ class ChunkIndex:
def iteritems(self): def iteritems(self):
yield from self.ht.iteritems() yield from self.ht.iteritems()
def get(self, key, default=None):
return self.ht.get(key, default)
def add(self, key, refs, size): def add(self, key, refs, size):
v = self.get(key, ChunkIndexEntry(0, 0)) v = self.get(key, ChunkIndexEntry(0, 0))
refcount = min(self.MAX_VALUE, v.refcount + refs) refcount = min(self.MAX_VALUE, v.refcount + refs)
self[key] = v._replace(refcount=refcount, size=size) 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): def compact(self):
return 0 return 0
@ -100,10 +97,7 @@ class FuseVersionsIndex:
return len(self.ht) return len(self.ht)
def get(self, key, default=None): def get(self, key, default=None):
try: return self.ht.get(key, default)
return self[key]
except KeyError:
return default
NSIndex1Entry = namedtuple('NSIndex1Entry', 'segment offset') NSIndex1Entry = namedtuple('NSIndex1Entry', 'segment offset')
@ -143,10 +137,7 @@ class NSIndex1:
return len(self.ht) return len(self.ht)
def get(self, key, default=None): def get(self, key, default=None):
try: return self.ht.get(key, default)
return self[key]
except KeyError:
return default
def pop(self, key, default=_NoDefault): def pop(self, key, default=_NoDefault):
try: try: