optimization

This commit is contained in:
Will McGugan
2023-01-08 22:32:09 +00:00
parent acb206046a
commit 204f3e48ed
2 changed files with 16 additions and 1 deletions

View File

@@ -276,7 +276,10 @@ class Compositor:
resized_widgets = { resized_widgets = {
widget widget
for widget, (region, *_) in changes for widget, (region, *_) in changes
if widget in common_widgets and old_map[widget].region.size != region.size if (
widget in common_widgets
and not old_map[widget].region.same_size(region)
)
} }
screen_region = size.region screen_region = size.region

View File

@@ -541,6 +541,18 @@ class Region(NamedTuple):
width2, height2 = size width2, height2 = size
return Region(x, y, min(width1, width2), min(height1, height2)) return Region(x, y, min(width1, width2), min(height1, height2))
def same_size(self, region: Region) -> bool:
"""Check if another region is the same size. Equivalent to `self.size == region.size`,
but a little faster.
Args:
region (Region): A region.
Returns:
bool: True if both regions are the same size, False if they are different sizes.
"""
return self[2:] == region[2:]
def expand(self, size: tuple[int, int]) -> Region: def expand(self, size: tuple[int, int]) -> Region:
"""Increase the size of the region by adding a border. """Increase the size of the region by adding a border.