mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[no ci] Begin caching of offsets
This commit is contained in:
@@ -442,6 +442,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
"""Cache for individual cells."""
|
"""Cache for individual cells."""
|
||||||
self._line_cache: LRUCache[LineCacheKey, Strip] = LRUCache(1000)
|
self._line_cache: LRUCache[LineCacheKey, Strip] = LRUCache(1000)
|
||||||
"""Cache for lines within rows."""
|
"""Cache for lines within rows."""
|
||||||
|
self._offset_cache: LRUCache[int, list[[tuple[RowKey, int]]]] = LRUCache(1)
|
||||||
|
"""Cached y_offset - key is update_count - see y_offsets property for more information"""
|
||||||
|
|
||||||
self._require_update_dimensions: bool = False
|
self._require_update_dimensions: bool = False
|
||||||
"""Set to re-calculate dimensions on idle."""
|
"""Set to re-calculate dimensions on idle."""
|
||||||
@@ -501,10 +503,14 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
|
|||||||
lands on, and the y-offset *within* that row. The length of the returned list
|
lands on, and the y-offset *within* that row. The length of the returned list
|
||||||
is therefore the total height of all rows within the DataTable."""
|
is therefore the total height of all rows within the DataTable."""
|
||||||
y_offsets: list[tuple[RowKey, int]] = []
|
y_offsets: list[tuple[RowKey, int]] = []
|
||||||
for row in self.ordered_rows:
|
if self._update_count in self._offset_cache:
|
||||||
row_key = row.key
|
y_offsets = self._offset_cache[self._update_count]
|
||||||
row_height = row.height
|
else:
|
||||||
y_offsets += [(row_key, y) for y in range(row_height)]
|
for row in self.ordered_rows:
|
||||||
|
row_key = row.key
|
||||||
|
row_height = row.height
|
||||||
|
y_offsets += [(row_key, y) for y in range(row_height)]
|
||||||
|
self._offset_cache = y_offsets
|
||||||
return y_offsets
|
return y_offsets
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user