Skip to content

Commit

Permalink
micro optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed May 19, 2024
1 parent cbcfd9b commit cc90dc5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/textual/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def set(self, key: CacheKey, value: CacheValue) -> None:
key: Key.
value: Value.
"""
link = self._cache.get(key)
if link is None:
if self._cache.get(key) is None:
head = self._head
if not head:
# First link references itself
Expand Down Expand Up @@ -148,8 +147,8 @@ def get(
Returns:
Either the value or a default.
"""
link = self._cache.get(key)
if link is None:

if (link := self._cache.get(key)) is None:
self.misses += 1
return default
if link is not self._head:
Expand All @@ -166,7 +165,7 @@ def get(

def __getitem__(self, key: CacheKey) -> CacheValue:
link = self._cache.get(key)
if link is None:
if (link := self._cache.get(key)) is None:
self.misses += 1
raise KeyError(key)
if link is not self._head:
Expand Down

0 comments on commit cc90dc5

Please sign in to comment.