Skip to content

Commit ef49f95

Browse files
committed
optimizations
1 parent 6da1804 commit ef49f95

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/textual/_node_list.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
from textual.widget import Widget
1515

1616

17+
_display_getter = attrgetter("display")
18+
_visible_getter = attrgetter("visible")
19+
20+
1721
class DuplicateIds(Exception):
1822
"""Raised when attempting to add a widget with an id that already exists."""
1923

@@ -194,7 +198,7 @@ def displayed(self) -> Sequence[Widget]:
194198
if self._displayed_nodes[0] != self._updates:
195199
self._displayed_nodes = (
196200
self._updates,
197-
[node for node in self._nodes if node.display],
201+
list(filter(_display_getter, self._nodes)),
198202
)
199203
return self._displayed_nodes[1]
200204

@@ -204,14 +208,14 @@ def displayed_and_visible(self) -> Sequence[Widget]:
204208
if self._displayed_visible_nodes[0] != self._updates:
205209
self._displayed_nodes = (
206210
self._updates,
207-
[node for node in self.displayed if node.visible],
211+
list(filter(_visible_getter, self.displayed)),
208212
)
209213
return self._displayed_nodes[1]
210214

211215
@property
212216
def displayed_reverse(self) -> Iterator[Widget]:
213217
"""Just the nodes where `display==True`, in reverse order."""
214-
return reversed(self.displayed)
218+
return filter(_display_getter, reversed(self._nodes))
215219

216220
if TYPE_CHECKING:
217221

src/textual/widgets/_footer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections import defaultdict
4+
from itertools import groupby
45
from typing import TYPE_CHECKING
56

67
import rich.repr

0 commit comments

Comments
 (0)