Skip to content

Commit

Permalink
Adjust Cache to simplify code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Aug 2, 2024
1 parent c56dd82 commit 603a48b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/util/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class FlexibleCache {
return;
}
auto newSize = _valueSizeGetter(*(*this)[key]);
auto& oldSize = _sizeMap.at(key);
auto& sizeInMap = _sizeMap.at(key);
// Entry has grown too big to completely keep within the cache or we can't
// fit it in the cache
if (_maxSizeSingleEntry < newSize ||
Expand All @@ -246,12 +246,12 @@ class FlexibleCache {
return;
}

if (newSize >= oldSize) {
_totalSizeNonPinned += newSize - oldSize;
} else {
_totalSizeNonPinned -= oldSize - newSize;
}
oldSize = newSize;
// `MemorySize` type does not allow for negative values, but they are safe
// here, so we do it in size_t instead and convert back.
_totalSizeNonPinned =
MemorySize::bytes(_totalSizeNonPinned.getBytes() -
sizeInMap.getBytes() + newSize.getBytes());
sizeInMap = newSize;
if (_totalSizePinned <= _maxSize) {
makeRoomIfFits(0_B);
}
Expand Down

0 comments on commit 603a48b

Please sign in to comment.